/**
  * Render form content
  * @return bool|string
  */
 public function __toString()
 {
     $this->init();
     $this->view->action = $this->_action;
     $this->view->method = $this->_method;
     $this->view->form = $this;
     return $this->view->render();
 }
 public function run()
 {
     $this->init();
     if (empty($this->_actionMethod)) {
         trigger_error('Action not defined in class ' . get_class($this) . '::run()', E_USER_ERROR);
         App::response()->sendNotFoundAndExit();
     }
     if (!method_exists($this, $this->_actionMethod)) {
         trigger_error('Action method "' . $this->_actionMethod . '" not exit in class ' . get_class($this) . '::run()', E_USER_ERROR);
         App::response()->sendNotFoundAndExit();
     }
     $this->{$this->_actionMethod}();
     if ($this->_doRender) {
         // if action method called render()
         return $this->view->render();
         // return rendered content
     } else {
         return $this->view->getData();
         // return all variables
     }
 }
 /**
  * @param $config array
  */
 public static function run($config)
 {
     static::$_config = $config;
     // initialize error handling
     register_shutdown_function(array('App', 'onFatalError'));
     set_exception_handler(array('App', 'onException'));
     set_error_handler(array('App', 'onError'));
     $response = App::response();
     // init response
     $response->enableBuffering();
     // start output buffering
     // initialize class Autoloader
     $autoloader = static::autoloader();
     // initialize Router
     $router = static::router();
     $parsedUrl = $router->parseRequestUrl(App::request()->getUrl());
     $controllerClassName = $parsedUrl['controller'];
     $actionMethodName = $parsedUrl['action'];
     $parameters = $parsedUrl['parameters'];
     if (!$autoloader->classDefined($controllerClassName)) {
         trigger_error('Controller "' . $controllerClassName . '" not found');
         App::response()->sendNotFoundAndExit();
     }
     /** @var $controller AppController */
     $controller = new $controllerClassName();
     $controller->setAction($actionMethodName);
     $controller->setParameters($parameters);
     // get response from action
     $actionContent = $controller->run();
     // get layout from controller
     $layout = $controller->getLayout();
     if ($layout) {
         // if layout not disabled ( @see AppController::disableLayout() )
         $layoutView = new AppView('layouts/' . $layout);
         $layoutView->title = static::$_config['applicationName'];
         $layoutView->content = $actionContent;
         // insert action response into page layout
         // render page
         echo $layoutView->render();
     }
     // send response to client
     App::response()->sendContent();
 }
Ejemplo n.º 4
0
 /**
  * Render the view path by extracting the render array
  *
  * @param String $__path_to_the_view_file the path to the view file
  * @param Object $render the data to render in the view
  * @return String the rendered output to be returned to the client
  */
 public static function render($__path_to_the_view_file, $render)
 {
     self::$render = $render;
     ob_start();
     extract((array) $render);
     include $__path_to_the_view_file;
     if (isset($php_errormsg) && isset($app) && $app instanceof App) {
         $app->add_error_message($php_errormsg);
     }
     return ob_get_clean();
 }