Example #1
0
 /**
  * Assign variable
  * @param  mixed          $key - can be string, dot notation k/v, or array to set data as bulk
  * @param  mixed          $val - can be string, numeric, array
  * @return Api
  */
 public function assign($key, $val = "")
 {
     if (is_string($key) || is_array($key)) {
         $data = array();
         if (is_string($key)) {
             if (preg_match("/\\./", $key)) {
                 // dot notation keys
                 Core\Helpers::setArrayToDotNotation($data, $key, $val);
             } else {
                 $data[$key] = $val;
             }
         } else {
             $data = $key;
         }
         $this->assigned = array_merge_recursive($data, $this->assigned);
         return $this;
     } else {
         throw new Core\Exception("Can't assign() {$key}. Invalid key type. Must be string or array");
     }
 }
Example #2
0
 /**
  * Return a CameLized string
  *
  * @return string
  */
 public static function formatName($name)
 {
     return Helpers::camelize($name, true);
 }
Example #3
0
 /**
  * Render the template
  *
  * @return String
  */
 public function render()
 {
     if ($this->getFormat() == self::FORMAT_JSON) {
         // RENDER AS JSON
         $this->unassign("_");
         //@deprecated _app.* in favor of _.*
         $this->unassign("_app");
         return json_encode($this->getAssigned());
     } else {
         // RENDER AS HTML
         // Content already rendered
         if ($this->renderedContent && $this->isRendered) {
             return $this->renderedContent;
         }
         // _.title
         if (isset($this->meta["title"])) {
             $this->assign_("title", $this->meta["title"]);
         }
         // _.flash_message
         $flashMessage = $this->getFlashMessage();
         if ($flashMessage) {
             $this->assign_("flash_message", $flashMessage);
             //@deprecated for naming convetion. Use flash_message
             $this->assign_("flashMessage", $flashMessage);
             $this->clearFlashMessage();
         }
         // _.error
         if ($this->hasError()) {
             $this->assign_("error", $this->getMessage("error"));
         }
         // _.*
         $this->assign_(["year" => date("Y"), "site_url" => $this->controller->getSiteUrl(), "base_url" => $this->controller->getBaseUrl(), "meta" => $this->meta, "shared_assets" => $this->getPublicAssetsDir(), "assets" => $this->getModuleAssetsDir(), "module_name" => $this->controller->getModuleName(), "module_url" => $this->controller->getModuleUrl(), "controller_name" => $this->controller->getControllerName(), "controller_url" => $this->controller->getControllerUrl(), "action_name" => $this->controller->getActionName(), "action_url" => $this->controller->getActionUrl(), "request_params" => $this->controller->getParams()]);
         $renderName = $this->templateKeys["view"];
         $this->addTemplate($this->templateKeys["view"], $this->actionView, $this->isActionViewAbsolute);
         if ($this->layout) {
             $renderName = $this->templateKeys["layout"];
             $this->addTemplate($this->templateKeys["layout"], $this->layout, $this->isLayoutAbsolute);
         }
         $this->isRendered = true;
         $this->parse();
         if (isset($this->templates[$renderName])) {
             $this->renderedContent = $this->engine->render($this->templates[$renderName], $this->getAssigned());
             // Strip HTML Comments
             if ($this->controller->getConfig("views.stripHtmlComments")) {
                 $this->renderedContent = Helpers::stripHtmlComments($this->renderedContent);
             }
         }
         return $this->renderedContent;
     }
 }
Example #4
0
 /**
  * Return a string to friendly url
  * @param  type   $url
  * @return string
  */
 public function toFriendlyUrl($url)
 {
     return Helpers::toFriendlyUrl($url);
 }