当前位置: 首页>>代码示例>>PHP>>正文


PHP Dispatcher::loadAction方法代码示例

本文整理汇总了PHP中Dispatcher::loadAction方法的典型用法代码示例。如果您正苦于以下问题:PHP Dispatcher::loadAction方法的具体用法?PHP Dispatcher::loadAction怎么用?PHP Dispatcher::loadAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Dispatcher的用法示例。


在下文中一共展示了Dispatcher::loadAction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: forward

 /**
  * Whilst in controller context, move to another controller/action.
  *
  * When forwarding to a new action or controller/action, the URL will not
  * change, this is an internal redirect.
  *
  * Forwarding to an action in the same controller
  *
  * <code>
  * $this->forward('newAction');
  * </code>
  *
  * Forwarding to a new controller and action.
  *
  * <code>
  * $this->forward('newAction', 'newController');
  * </code>
  *
  * @access public
  * @param  string    $action     The action we wish to forward to.
  * @param  string    $controller The controller we wish to forward to.
  * @throws Exception             From the Dispatcher if the controller/action does not exist.
  */
 public function forward($action = 'index', $controller = '')
 {
     // Reregister the action in the profile
     Profiler::deregister('Action', $this->view->action);
     // Set which controller has called this function. If it is the same as
     // .. the user specified controller then we do not need to instantiate
     // .. a whole new controller, we can simply forward to its action
     $controllerCaller = str_replace(Config::get('settings', 'project') . '\\Controller\\', '', get_called_class());
     // Calling an action in the same controller
     if ($controller == '' || $controller == $controllerCaller) {
         Dispatcher::loadAction($this->child, $action);
     } else {
         Profiler::deregister('Controller', $this->view->controller);
         Dispatcher::loadController($controller, $action);
     }
 }
开发者ID:johann-weiss,项目名称:MVC,代码行数:39,代码来源:Controller.php

示例2: loadAction

 /**
  * Load a controllers action, and ask the View to render it.
  *
  * @access public
  * @param  object  $controller Controller object that we want to load the action for.
  * @param  string  $action     Name of the action we wish to load.
  * @static
  */
 public static function loadAction($controller, $action)
 {
     // Start the profiler
     Profiler::register('Core', 'Dispatcher');
     // In order to have pretty URL's we allow the basic routing to contain
     // .. dashes in their action names which will be removed here. It allows
     // .. /index/hello-world to be routed to /index/helloworld.
     $action = str_replace('-', '', $action);
     $actionExists = is_callable(array($controller, $action . 'Action'));
     $controllerName = str_replace(Config::get('settings', 'project') . '\\Controller\\', '', get_class($controller));
     // Make sure that the controller has the action
     if (!$actionExists) {
         // If this is the error controller then there is no hope
         if ($controllerName == 'Error') {
             die('Sorry, an error occurred whilst processing your request.');
         } else {
             if ($action != 'error') {
                 Profiler::deregister('Core', 'Dispatcher');
                 Dispatcher::loadAction($controller, 'error');
             } else {
                 Profiler::deregister('Core', 'Dispatcher');
                 Profiler::deregister('Controller', $controllerName);
                 Dispatcher::loadController('Error', 'notFound');
             }
         }
     }
     // We are able to call the controllers action
     Event::trigger('initAction', array('controller' => $controller, 'action' => $action));
     Profiler::deregister('Core', 'Dispatcher');
     Profiler::register('Action', $action);
     // Set the controller and action that we are heading to
     $controller->view->controller = $controllerName;
     $controller->view->action = $action;
     // Call and render this action
     $controller->{$action . 'Action'}();
     $controller->view->render();
 }
开发者ID:johann-weiss,项目名称:MVC,代码行数:45,代码来源:Dispatcher.php


注:本文中的Dispatcher::loadAction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。