Example #1
0
 /**
  * Load view from controller action with default layout
  *
  * @throws Orc If main template not exists
  */
 public function loadView()
 {
     $layoutFile = Config::get('layout') . '.phtml';
     $layoutPath = APP_DIR . DS . 'layout' . DS . $layoutFile;
     if (file_exists($layoutPath)) {
         require_once $layoutPath;
     } else {
         throw new Orc('Layout template does not exists: ' . $layoutFile);
     }
 }
Example #2
0
 /**
  * Call controller action
  * 
  * @param string $action Action name
  * @param string $controller Controller name
  * @param mixed $params Action params
  */
 public function action($action, $controller, $params = [])
 {
     // Add given params into request
     $request = Request::load();
     foreach ($params as $key => $value) {
         $request->setParam($key, $value);
     }
     // Route to new controller action
     $request->setIsInternal();
     Router::load()->route($request->setUri(Config::get('base_path') . $controller . '/' . $action));
 }
Example #3
0
 /**
  * Register routes
  */
 private function __construct()
 {
     $basePath = Config::get('base_path');
     // Main route: slimfit.com
     $mainRoute = [rtrim($basePath, '/') => []];
     // Controller route: slimfit.com/user
     $controllerRoute = [$basePath . '{:class}' => ['class']];
     // Action route: slimfit.com/user/add
     $actionRoute = [$basePath . '{:class}/{:method}' => ['class', 'method']];
     // Param route: slimfit.com/user/get/23
     $paramRoute = [$basePath . '{:class}/{:method}/{:id}' => ['class', 'method', 'id']];
     $this->addRoutes([$mainRoute, $controllerRoute, $actionRoute, $paramRoute]);
     // Set controller path
     $this->classPath = APP_DIR . DS . 'controllers';
 }
Example #4
0
 /**
  * Run Application
  */
 public static function run()
 {
     // Set application config
     Config::init();
     // Route to controller action
     Router::load()->route(Request::load());
 }