本文整理匯總了PHP中Zend\Mvc\MvcEvent::setController方法的典型用法代碼示例。如果您正苦於以下問題:PHP MvcEvent::setController方法的具體用法?PHP MvcEvent::setController怎麽用?PHP MvcEvent::setController使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\Mvc\MvcEvent
的用法示例。
在下文中一共展示了MvcEvent::setController方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: onRoute
/**
* Global Route /module/controller/action
* @param MvcEvent $e
*/
public function onRoute(MvcEvent $e)
{
$matches = $e->getRouteMatch();
$module = $matches->getParam('module');
$controller = $matches->getParam('controller');
if ($module && $controller && strpos($controller, '\\') === false) {
$matches->setParam(self::ORIGINAL_CONTROLLER, $controller);
$controllerLoader = $e->getApplication()->getServiceManager()->get('ControllerManager');
$ctrlClass = $this->convertName($module) . '\\Controller\\';
$ctrlClass .= $this->convertName($controller);
$controller = $ctrlClass;
$matches->setParam('controller', $controller);
$ctrlClass .= 'Controller';
if (!$controllerLoader->has($controller) && class_exists($ctrlClass)) {
$controllerLoader->setInvokableClass($controller, $ctrlClass);
$e->setController($controller);
$e->setControllerClass($ctrlClass);
}
}
}
示例2: test404ResponsePrepares404ViewModelWithControllerWhenAllowed
public function test404ResponsePrepares404ViewModelWithControllerWhenAllowed()
{
$response = new Response();
$event = new MvcEvent();
$controller = 'some-or-other';
$controllerClass = 'Some\\Controller\\OrOtherController';
$event->setController($controller);
$event->setControllerClass($controllerClass);
foreach (array('setDisplayNotFoundReason', 'setDisplayExceptions') as $method) {
foreach (array(true, false) as $allow) {
$this->strategy->{$method}($allow);
$response->setStatusCode(404);
$event->setResult(null);
$event->setResponse($response);
$this->strategy->prepareNotFoundViewModel($event);
$model = $event->getResult();
$this->assertInstanceOf('Zend\\View\\Model\\ModelInterface', $model);
$variables = $model->getVariables();
if ($allow) {
$this->assertTrue(isset($variables['controller']));
$this->assertEquals($controller, $variables['controller']);
$this->assertTrue(isset($variables['controller_class']));
$this->assertEquals($controllerClass, $variables['controller_class']);
} else {
$this->assertFalse(isset($variables['controller']));
$this->assertFalse(isset($variables['controller_class']));
}
}
}
}
示例3: marshalMiddlewareNotCallable
/**
* Marshal a middleware not callable exception event
*
* @param string $type
* @param string $middlewareName
* @param MvcEvent $event
* @param Application $application
* @param \Exception $exception
* @return mixed
*/
protected function marshalMiddlewareNotCallable($type, $middlewareName, MvcEvent $event, Application $application, \Exception $exception = null)
{
$event->setName(MvcEvent::EVENT_DISPATCH_ERROR);
$event->setError($type);
$event->setController($middlewareName);
$event->setControllerClass('Middleware not callable: ' . $middlewareName);
if ($exception !== null) {
$event->setParam('exception', $exception);
}
$events = $application->getEventManager();
$results = $events->triggerEvent($event);
$return = $results->last();
if (!$return) {
$return = $event->getResult();
}
return $return;
}
示例4: marshalBadControllerEvent
/**
* Marshal a bad controller exception event
*
* @param string $controllerName
* @param MvcEvent $event
* @param Application $application
* @param \Throwable|\Exception $exception
* @return mixed
*/
protected function marshalBadControllerEvent($controllerName, MvcEvent $event, Application $application, $exception)
{
$event->setName(MvcEvent::EVENT_DISPATCH_ERROR);
$event->setError($application::ERROR_EXCEPTION);
$event->setController($controllerName);
$event->setParam('exception', $exception);
$events = $application->getEventManager();
$results = $events->triggerEvent($event);
$return = $results->last();
if (!$return) {
return $event->getResult();
}
return $return;
}