本文整理汇总了PHP中Zend\Mvc\MvcEvent::getController方法的典型用法代码示例。如果您正苦于以下问题:PHP MvcEvent::getController方法的具体用法?PHP MvcEvent::getController怎么用?PHP MvcEvent::getController使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Mvc\MvcEvent
的用法示例。
在下文中一共展示了MvcEvent::getController方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleError
/**
*
*/
public function handleError(MvcEvent $event)
{
$controller = $event->getController();
$error = $event->getParam('error');
$exception = $event->getParam('exception');
$message = sprintf('Error dispatching controller "%s". Error was: "%s"', $controller, $error);
if ($exception instanceof \Exception) {
$message .= ', Exception(' . $exception->getMessage() . '): ' . $exception->getTraceAsString();
}
error_log($message);
}
示例2: injectController
/**
* Inject the controller and controller class into the model
*
* If either $displayExceptions or $displayNotFoundReason are enabled,
* injects the controllerClass from the MvcEvent. It checks to see if a
* controller is present in the MvcEvent, and, if not, grabs it from
* the route match if present; if a controller is found, it injects it into
* the model.
*
* @param ViewModel $model
* @param MvcEvent $e
* @return void
*/
protected function injectController($model, $e)
{
if (!$this->displayExceptions() && !$this->displayNotFoundReason()) {
return;
}
$controller = $e->getController();
if (empty($controller)) {
$routeMatch = $e->getRouteMatch();
if (empty($routeMatch)) {
return;
}
$controller = $routeMatch->getParam('controller', false);
if (!$controller) {
return;
}
}
$controllerClass = $e->getControllerClass();
$model->setVariable('controller', $controller);
$model->setVariable('controller_class', $controllerClass);
}
示例3: onDispatch
/**
* General dispatch listener
*
* @param \Zend\Mvc\MvcEvent $event
*/
public function onDispatch(MvcEvent $event)
{
if ($this->response) {
$event->stopPropagation();
return $this->response;
}
$routeMatch = $event->getRouteMatch();
$sm = $event->getApplication()->getServiceManager();
// Set current timezone, when first get
$sm->get('Timezone');
if ($routeMatch) {
$locale = $routeMatch->getParam('locale');
}
if (!$locale) {
$request = $event->getRequest();
if ($request instanceof HttpRequest) {
$header = $request->getHeader('Accept-Language');
if ($header) {
$availables = null;
$controller = $event->getController();
if ($controller instanceof LocaleSelectorInterface) {
$availables = $controller->getAvailableLocales();
}
$locale = $sm->get('Locale')->acceptFromHttp($header->getFieldValue(), $availables);
}
}
}
if ($locale) {
$sm->get('Locale')->setCurrent($locale);
}
}
示例4: detectError
public function detectError(MvcEvent $event)
{
$result = $event->getResult();
if ($result instanceof ResponseInterface) {
// Already have a response as the result
return;
}
$error = $event->getError();
$ex = $event->getParam('exception');
switch ($error) {
case Application::ERROR_CONTROLLER_NOT_FOUND:
$message = ucfirst($event->getControllerClass());
$ex = new RdnException\RuntimeException($message, 500, $ex);
break;
case Application::ERROR_CONTROLLER_INVALID:
$message = $event->getController() . ' is not dispatchable';
$ex = new RdnException\RuntimeException($message, 500, $ex);
break;
case Application::ERROR_ROUTER_NO_MATCH:
$message = 'Request did not match any routes.';
$ex = new RdnException\NotFoundException($message, 404, $ex);
break;
}
if (isset($message)) {
if ($ex->getCode() == 500) {
$event->setError(Application::ERROR_EXCEPTION);
}
$event->setParam('exception', $ex);
}
}