本文整理汇总了PHP中Phalcon\Mvc\Dispatcher::forward方法的典型用法代码示例。如果您正苦于以下问题:PHP Dispatcher::forward方法的具体用法?PHP Dispatcher::forward怎么用?PHP Dispatcher::forward使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Mvc\Dispatcher
的用法示例。
在下文中一共展示了Dispatcher::forward方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeExecuteRoute
/**
* Execute before the router so we can determine if this is a provate controller, and must be authenticated, or a
* public controller that is open to all.
*
* @param 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->flash->notice('You don\'t have access to this module: private');
$dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
return false;
}
// 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: beforeExecuteRoute
/**
* 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 Dispatcher $dispatcher
* @return boolean
*/
public function beforeExecuteRoute(Dispatcher $dispatcher)
{
$controllerName = $dispatcher->getControllerName();
// this is not namespaced
$controllerName = $dispatcher->getHandlerClass();
// this IS namespaced
// Only check permissions on private controllers
// By virtue of extending BaseAuth, this is a private controller
// 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->warning('Please sign in.');
$dispatcher->forward(array('controller' => 'session', 'action' => 'login'));
return false;
}
//$this->flash->notice( \Dsc\Lib\Debug::dump( $identity ) );
// Check if the user have permission to the current option
$actionName = $dispatcher->getActionName();
if (!$this->acl->isAllowed($identity['profile'], $controllerName, $actionName)) {
$this->flash->warning('You don\'t have access to: ' . $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;
}
}
示例3: __construct
public function __construct(Dispatcher $dispatcher, $exception)
{
if ($exception instanceof DispatchException) {
$dispatcher->forward(array('module' => 'index', 'controller' => 'error', 'action' => 'error404'));
return false;
}
$dispatcher->forward(array('module' => 'index', 'controller' => 'error', 'action' => 'error503'));
return false;
}
示例4: beforeException
public function beforeException(Event $event, Dispatcher $dispatcher, $exception)
{
//Handle 404 exceptions
if ($exception instanceof DispatchException) {
$dispatcher->forward(array('controller' => 'index', 'action' => 'show404'));
return false;
}
//Handle other exceptions
$dispatcher->forward(array('controller' => 'index', 'action' => 'show503'));
return false;
}
示例5: beforeException
public function beforeException(\Phalcon\Events\Event $event, \Phalcon\Mvc\Dispatcher $dispatcher, \Phalcon\Exception $exception)
{
switch ($exception->getCode()) {
case $dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case $dispatcher::EXCEPTION_ACTION_NOT_FOUND:
$dispatcher->forward(array('controller' => 'error', 'action' => 'notFound'));
return false;
default:
$dispatcher->forward(array('controller' => 'error', 'action' => 'uncaughtException'));
return false;
}
}
示例6: beforeException
/**
* This action is executed before execute any action in the application
*
* @param Event $event
* @param Dispatcher $dispatcher
*/
public function beforeException(Event $event, MvcDispatcher $dispatcher, Exception $exception)
{
if ($exception instanceof DispatcherException) {
switch ($exception->getCode()) {
case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
$dispatcher->forward(array('controller' => 'errors', 'action' => 'show404'));
return false;
}
}
$dispatcher->forward(array('controller' => 'errors', 'action' => 'show500'));
return false;
}
示例7: beforeException
/**
* This action is executed before execute any action in the application
*
* @param Event $event
* @param MvcDispatcher $dispatcher
* @param Exception $exception
* @return boolean
*/
public function beforeException(Event $event, MvcDispatcher $dispatcher, DispatcherException $exception)
{
error_log($exception->getMessage() . PHP_EOL . $exception->getTraceAsString());
if ($exception instanceof DispatcherException) {
switch ($exception->getCode()) {
case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
$dispatcher->forward(array('controller' => 'error', 'action' => 'error404'));
return false;
}
}
$dispatcher->forward(array('controller' => 'errors', 'action' => 'show500'));
return false;
}
示例8: beforeException
/**
* This action is executed before execute any action in the application
*
* @param Event $event
* @param Dispatcher $dispatcher
* @param DispatcherException $exception
*/
public function beforeException(Event $event, MvcDispatcher $dispatcher, $exception)
{
$object = $event->getData();
$this->view->setVar('message', $object->getMessage());
switch ($exception->getCode()) {
case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
$dispatcher->forward(array('controller' => 'error', 'action' => 'show404'));
return false;
case Dispatcher::EXCEPTION_CYCLIC_ROUTING:
$dispatcher->forward(['controller' => 'errors', 'action' => 'reports']);
return false;
}
}
示例9: beforeDispatch
public function beforeDispatch(Event $event, Dispatcher $dispatcher)
{
$di = PhDi::getDefault();
// global config
$config = $di['config'];
// Take the active controller/action from the dispatcher
$controller = $dispatcher->getControllerName();
$action = $dispatcher->getActionName();
// No ACL checks for AccessController
if ($controller == 'access') {
return true;
}
// Check whether the "auth" variable exists in session to define the active role
$auth = $this->session->get('auth');
if (!$auth) {
// user not logged in
$dispatcher->forward(array('controller' => 'access', 'action' => 'signin'));
return false;
} else {
$role = $auth['role'];
}
// Check whether acl data already exist
$aclFileName = $config->application['securityDir'] . "acl.data";
if (!is_file($aclFileName)) {
// Obtain the ACL list
$acl = $this->getAcl();
// Store serialized list into plain file
file_put_contents($aclFileName, serialize($acl));
} else {
//Restore acl object from serialized file
$acl = unserialize(file_get_contents($aclFileName));
}
// Check if the Role have access to the controller (resource)
$allowed = $acl->isAllowed($role, $controller, $action);
if ($allowed != Acl::ALLOW) {
// If user doesn't have access forward to the index controller
$flashMessage = <<<EOT
<div class="alert alert-block alert-danger">
<a class="close" data-dismiss="alert" href="#">×</a>
<h4 class="alert-heading">Error!</h4>
You don't have access to this module.
</div>
EOT;
$this->flashSession->warning($flashMessage);
$dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
// Returning "false" will tell to the dispatcher to stop the current operation
return false;
}
}
示例10: beforeException
public function beforeException(Event $event, MvcDispatcher $dispatcher, Exception $exception)
{
if ($exception instanceof DispatcherException) {
switch ($exception->getCode()) {
//en caso de que el servicio llamado no sea encontrado o la acción no se encuentre
case PhDispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case PhDispatcher::EXCEPTION_ACTION_NOT_FOUND:
//con dispatcher->forward le decimos que muestre el contenido de la acción show404 del controlador error, a crearlo
$dispatcher->forward(array('controller' => 'error', 'action' => 'show404'));
return false;
}
}
$dispatcher->forward(array('controller' => 'error', 'action' => 'show500'));
return false;
}
示例11: beforeExecuteRoute
public function beforeExecuteRoute(Event $event, Dispatcher $dispatcher)
{
$auth = $this->session->get('auth');
if (!$auth) {
$role = 'INVITADO';
} else {
$role = $auth["rol_nombre"];
}
//nombre del controlador al que intentamos acceder
$controller = $dispatcher->getControllerName();
//nombre de la acción a la que intentamos acceder
$action = $dispatcher->getActionName();
//obtenemos la Lista de Control de Acceso(acl) que hemos creado
$acl = $this->getAcl();
//boolean(true | false) si tenemos permisos devuelve true en otro caso false
$allowed = $acl->isAllowed($role, $controller, $action);
//si el usuario no tiene acceso a la zona que intenta acceder
//se lo redirecciona a login. (o habria que enviarlo al index? )
//con un mensaje flash
if ($allowed != \Phalcon\Acl::ALLOW) {
$this->flash->error("<p>ZONA RESTRINGIDA, NO TIENES PERMISO PARA ACCEDER A LA SECCIÓN SOLICITADA</p>");
$dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
return false;
}
}
示例12: beforeDispatch
public function beforeDispatch(Event $event, Dispatcher $dispatcher)
{
//check whether the 'auth' variable exists in session (if logged in)
$auth = $this->session->get('auth');
if ($auth) {
//logged in
$role = 'Users';
} else {
//not logged in
$role = 'Guests';
}
//take the active controller/action from the dispatcher
$controller = $dispatcher->getControllerName();
$action = $dispatcher->getActionName();
//obtain the ACL list
$acl = $this->getAcl(false);
//check if the role has access to the controller (resource)
$allowed = $acl->isAllowed($role, $controller, $action);
if ($allowed != Acl::ALLOW) {
//does not have access to the controller, fwd to index
$this->flashSession->error("{$role} don't have access to this page!");
$dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
//return false to tell dispatcher to stop current operation
return false;
} else {
//user is allowed in (do nothing)
if ($controller == 'admin' && $action == 'updateAcl') {
//update acl
$acl = $this->getAcl(true);
}
}
}
示例13: beforeExecuteRoute
/**
* @param Dispatcher $dispatcher
*/
public function beforeExecuteRoute(Dispatcher $dispatcher)
{
$controllerName = $dispatcher->getControllerName();
$actionName = $dispatcher->getActionName();
// This confirm a private zone
//check for a closed controller and Action is exist a current session
if ($this->acl->isClosed($controllerName, $actionName)) {
if (!is_null($this->auth->getAccess())) {
//This redirect to another Controller/Action
$this->response->redirect('dashboard');
// Disable the view to avoid rendering
$this->view->disable();
}
return true;
}
if ($this->acl->isPrivate($controllerName)) {
if (!is_null($this->auth->getAccess())) {
//echo "Logeado";
} else {
//Display a error by a flash component
$this->flash->notice('Upss! Access denied, Please Registry first or Login into Kangoo');
//Execute the dispatcher to move above the user
$dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
return false;
}
}
}
示例14: beforeDispatch
/**
* This action is executed before execute any action in the application
*/
public function beforeDispatch(Event $event, Dispatcher $dispatcher)
{
if ($this->config->application->user_login_form_cookies) {
//use cookies
$auth = $this->_getCookie('auth');
if (!$auth) {
$role = 'Guests';
} else {
$role = $this->_getCookie('role');
$role = 'Person';
}
} else {
$auth = $this->session->get('auth');
$auth = $this->_getCookie('auth');
if (!$auth) {
$role = 'Guests';
} else {
$role = $auth['role'];
// $role='Common';
}
}
$controller = $dispatcher->getControllerName();
$action = $dispatcher->getActionName();
$acl = $this->getAcl();
$allowed = $acl->isAllowed($role, $controller, $action);
if ($allowed != Acl::ALLOW) {
$this->flash->error("You don't have access to this module");
$dispatcher->forward(array('controller' => 'user', 'action' => 'login'));
return false;
}
}
示例15: beforeExecuteRoute
/**
* @param Dispatcher $dispatcher
*
* @return bool
*/
public function beforeExecuteRoute(Dispatcher $dispatcher)
{
$returnVal = true;
$lang = $this->getUriParameter('language');
$controllerName = $dispatcher->getControllerName();
if ('1' != $this->config->application->debug) {
$lang = $this->getUriParameter('language');
$lang = $lang ? $lang : 'en';
$key = preg_replace('/[^a-zA-Z0-9\\_]/', '', $lang . '-' . $dispatcher->getControllerName() . '-' . $dispatcher->getActionName() . '-' . implode('-', $dispatcher->getParams()));
$this->view->cache(array('key' => $key));
if ($this->view->getCache()->exists($key)) {
$returnVal = false;
}
}
$auth = $this->session->get('auth');
$identity = $this->auth->getIdentity();
if (!$auth) {
$role = 'Guests';
} else {
$role = $identity['profile'];
}
// Check if the user have permission to the current option
$actionName = $dispatcher->getActionName();
if (!$this->acl->isAllowed($role, $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'));
}
$returnVal = false;
} else {
$this->requestInitialize($controllerName);
}
return $returnVal;
}