Ejemplo n.º 1
0
 /**
  * Renders a HTML view. It loads the corresponding view automatically
  * The naming convention for a view is Application::index() opens views/application/index.html
  * and views/main.html have to exists as master template. You can overwrite
  * template and master template with optional parameters. The method extracts all elements
  * of $renderArgs to local variables which may be used in the template
  *
  * @static
  * @param array $renderArgs optional an associative array of values
  * @param string $template optional a file name like 'views/test/test.html' which overwrites the default
  * @param int $httpCode
  * @param string $masterTemplate optional a file name like 'views/test/test.html' which overwrites the default master
  * @return bool
  */
 public static function render($renderArgs = array(), $template = null, $httpCode = 200, $masterTemplate = null)
 {
     http_response_code($httpCode);
     self::setRenderArgs($renderArgs, true);
     extract(self::$renderArgs);
     $app = LVC::get();
     if ($template) {
         $app->view = $app->config->appPath . $template;
     } else {
         $app->view = self::searchView(LVC::camelCaseTo($app->controller) . '/' . LVC::camelCaseTo($app->actionName) . '.html');
     }
     if (!is_null($masterTemplate)) {
         $masterTemplate = $app->config->appPath . $masterTemplate;
     } else {
         $masterTemplate = self::searchView('main.html');
     }
     include $masterTemplate;
     return true;
 }
Ejemplo n.º 2
0
Archivo: LVC.php Proyecto: scandio/lmvc
 /**
  * generates an URI from a static class method with parameters
  * from uri('Application::index', $var) you get the URI
  * /app/path/controller/action/{$var}
  *
  * also accepts absolute paths like '/public/stylesheets/style.css' and directly returns them for convenience.
  *
  * @param string $method method name in static syntax like 'Application::index'
  * @param string|array $params single value or array of parameters
  * @return string the URI
  */
 public function uri($method, $params = null)
 {
     if (is_string($method) && substr($method, 0, 1) === '/') {
         return $method;
     }
     if ($params && !is_array($params)) {
         $params = array($params);
     }
     $method = explode('::', $method);
     $controller = $method[0] == 'Application' ? '/' : '/' . LVC::camelCaseTo($method[0]);
     $action = $method[1] == 'index' ? '/' : '/' . LVC::camelCaseTo($method[1]);
     return $this->uri . ($controller == '/' && $action != '/' ? '' : $controller) . ($action == '/' ? '' : $action) . ($params ? ($controller == '/' && $action == '/' ? '' : '/') . implode('/', $params) : '');
 }