Esempio n. 1
0
 /**
  * Dispatches given action. Executes controllers action and render it's view.
  *
  * TODO: 
  *   1) Add the way to disable standart view rendering.
  * 
  * @param string $controller
  * @param string $action
  */
 public static function dispatch($controller = null, $action = null)
 {
     if (is_null($controller)) {
         $controller = 'Index';
     }
     if (is_null($action)) {
         $action = 'default';
     }
     if (!preg_match('#[a-zA-Z0-9\\-_]{1,100}#', $action)) {
         throw new Exception("Action name '{$action}' include bad characters", 404);
     }
     if (!file_exists("./controllers/{$controller}Controller.php")) {
         throw new Exception("Controller '{$controller}' not found", 404);
     }
     require_once "./controllers/{$controller}Controller.php";
     if (!class_exists($controller . 'Controller')) {
         throw new Exception("Controller class {$controller}Controller was not found", 404);
     }
     $className = $controller . 'Controller';
     $controllerInstance = new $className();
     if (!method_exists($controllerInstance, $action . 'Action')) {
         throw new Exception("Action {$action}Action was not found in controller {$controller}Controller", 404);
     }
     self::setViewScript(strtolower($controller) . '/' . $action);
     $controllerInstance->{$action . 'Action'}();
     if (true != self::$_noRender) {
         $body = self::getView()->render(self::getViewScript());
         $page = new Lpf_View();
         $page->body = $body;
         $page->title = Config::SERVICE_NAME;
         $page->render('page', false);
     }
 }
Esempio n. 2
0
 /**
  * Builds, renders menu and returns it's HTML-code.
  * @return string
  */
 public function __invoke(array $elements = null, $active = null)
 {
     if (is_null($elements)) {
         $elements = $this->_elements;
     }
     if (is_null($active)) {
         $active = $this->_activeElement;
     }
     $view = new Lpf_View();
     $view->elements = $elements;
     $view->active = $active;
     return $view->render($this->_template, true);
 }