示例#1
0
 /**
  * Execute before the router so we can determine if this is a private controller, and must be authenticated, or a
  * public controller that is open to all.
  *
  * @param \Phalcon\Dispatcher $dispatcher
  * @return boolean
  */
 public function beforeExecuteRoute(Dispatcher $dispatcher)
 {
     $controllerName = $dispatcher->getControllerName();
     // Only check permissions on private controllers
     if ($this->acl->isPrivate($controllerName)) {
         // Get the current identity
         $identity = $this->auth->getIdentity();
         // If there is no identity available the user is redirected to index/index
         if (!is_array($identity)) {
             $this->flashSession->notice('You are not logged in!');
             return $this->redirect('session/login');
         }
         //			// Check if the user have permission to the current option
         //			$actionName = $dispatcher->getActionName();
         //			if (!$this->acl->isAllowed($identity['profile'], $controllerName, $actionName)) {
         //
         //				$this->flash->notice('You don\'t have access to this module: ' . $controllerName . ':' . $actionName);
         //
         //				if ($this->acl->isAllowed($identity['profile'], $controllerName, 'index')) {
         //					$dispatcher->forward(array(
         //						'controller' => $controllerName,
         //						'action' => 'index'
         //					));
         //				} else {
         //					$dispatcher->forward(array(
         //						'controller' => 'user_control',
         //						'action' => 'index'
         //					));
         //				}
         //
         //				return false;
         //			}
     }
 }
示例#2
0
 /**
  * Pulls all the data that might be in the url and saves it here
  *
  * @param Phalcon\Mvc\Dispatcher $dispatcher
  * @param array $map
  * @param array $default{order_by, order, limit}
  */
 public function __construct(Phalcon\Dispatcher $dispatcher, array $map = array(), $default = array())
 {
     $di = Phalcon\DI::getDefault();
     // Set page
     if ($di->get('request')->hasQuery('page') && $di->get('request')->getQuery('page', array('int'))) {
         $this->page = $di->get('request')->getQuery('page', array('int'));
     }
     // Set limit
     if ($di->get('request')->hasQuery('limit') && $di->get('request')->getQuery('limit', array('int'))) {
         $this->limit = $di->get('request')->getQuery('limit', array('int'));
     } else {
         if (isset($default['limit'])) {
             $this->limit = $default['limit'];
         }
     }
     // Map values
     foreach ($map as $k => $v) {
         $p = $dispatcher->getParam($k);
         if ($p !== null) {
             $p = (int) (bool) $p;
             //force it to be 0 or 1
             $this->query = "{$v} " . self::$sort[$p];
             $this->pageLink = "/{$k}/" . (int) $p;
             $this->orderColumn = $k;
             $this->order = (int) $p;
             break;
         }
     }
     // Set default values if nothing set
     if ($this->query === NULL && count((array) $default)) {
         if (count($map) && isset($default['order_by']) && isset($map[$default['order_by']])) {
             $this->query = $map[$default['order_by']] . ' ' . self::$sort[(int) (bool) $default['order']];
             $this->orderColumn = $default['order_by'];
             $this->order = (int) (bool) $default['order'];
         } else {
             if (isset($default['order_by'])) {
                 // Pass complex order
                 if (is_array($default['order_by'])) {
                     $order = array();
                     foreach ($default['order_by'] as $k => $v) {
                         $order_by[] = isset($default['order'][$k]) ? $v . ' ' . self::$sort[(int) (bool) $default['order'][$k]] : $v . ' ' . self::$sort[$default['order']];
                     }
                     $this->orderColumn = $default['order_by'][0];
                     $this->order = (array) $default['order'][0];
                     $this->query = implode(', ', $order_by);
                 } else {
                     $this->query = $default['order_by'] . ' ' . self::$sort[(int) (bool) $default['order']];
                     $this->orderColumn = $default['order_by'];
                     $this->order = (int) (bool) $default['order'];
                 }
             }
         }
     }
     if ($dispatcher instanceof Phalcon\Mvc\Dispatcher) {
         $this->baseLink = $dispatcher->getControllerName() . '/' . $dispatcher->getActionName();
     }
 }
示例#3
0
 /**
  * Forward event if required
  *
  * @param   Dispatcher Current dispatcher
  **/
 protected function forward(Dispatcher $dispatcher)
 {
     if (is_array($this->forwards)) {
         if (Phalcana::$isCli) {
             echo "HTTP Error: " . $this->code;
             echo ' - ' . $this->message . PHP_EOL;
             exit;
         }
         if (isset($this->forwards['namespace'])) {
             $dispatcher->setNamespaceName($this->forwards['namespace']);
         } else {
             $dispatcher->setNamespaceName('Phalcana\\Controllers');
         }
         $dispatcher->setControllerName($this->forwards['controller']);
         $dispatcher->setActionName($this->forwards['action']);
         $controller = $dispatcher->dispatch();
         $view = $controller->view;
         $view->start();
         // Render the related views
         $view->render($dispatcher->getControllerName(), $dispatcher->getActionName(), $dispatcher->getParams());
         // Finish the view
         $view->finish();
         $response = $controller->response;
         // Pass the output of the view to the response
         $response->setContent($view->getContent());
         // Send the request headers
         $response->sendHeaders();
         // Print the response
         echo $response->getContent();
         exit(1);
     }
     return true;
 }