本文整理匯總了PHP中Phalcon\Mvc\Dispatcher::setDefaultAction方法的典型用法代碼示例。如果您正苦於以下問題:PHP Dispatcher::setDefaultAction方法的具體用法?PHP Dispatcher::setDefaultAction怎麽用?PHP Dispatcher::setDefaultAction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Phalcon\Mvc\Dispatcher
的用法示例。
在下文中一共展示了Dispatcher::setDefaultAction方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: function
$eventsManager = $di->getShared('eventsManager');
//Attach a listener for type "dispatch"
$eventsManager->attach("dispatch", function () {
new Security();
});
$eventsManager->attach('dispatch:beforeException', function ($event, $dispatcher, $exception) {
switch ($exception->getCode()) {
case PhDispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case PhDispatcher::EXCEPTION_ACTION_NOT_FOUND:
$dispatcher->forward(['controller' => 'error', 'action' => 'route404']);
return false;
}
});
$dispatcher = new Phalcon\Mvc\Dispatcher();
$dispatcher->setDefaultController('Index');
$dispatcher->setDefaultAction('index');
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
}, true);
/**
* Translate
*/
$di->set('t', function () use($di) {
//Ask browser what is the best language
$language = $di->getShared('request')->getBestLanguage();
//Check if we have a translation file for that lang
if (file_exists(__DIR__ . "/../messages/" . $language . ".php")) {
$messages = (require __DIR__ . "/../messages/" . $language . ".php");
} else {
// fallback to some default
$messages = (require __DIR__ . "/../messages/zh-cn.php");