本文整理汇总了PHP中Phalcon\Mvc\Dispatcher::setDefaultController方法的典型用法代码示例。如果您正苦于以下问题:PHP Dispatcher::setDefaultController方法的具体用法?PHP Dispatcher::setDefaultController怎么用?PHP Dispatcher::setDefaultController使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Mvc\Dispatcher
的用法示例。
在下文中一共展示了Dispatcher::setDefaultController方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: function
$di->set('dispatcher', function () use($di) {
$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
示例2: registerServices
/**
* Register services
*
* @param DiInterface $di
*/
public final function registerServices(DiInterface $di)
{
$module = $this->module;
$baseControllers = $this->baseControllers;
//Registering a dispatcher
$di->set('dispatcher', function () use($di, &$module, &$baseControllers) {
//Create new Dispatcher
$dispatcher = new PDispatcher();
//Set default namespace to this module
$dispatcher->setModuleName($this->module);
//Set default namespace
$dispatcher->setDefaultNamespace($baseControllers);
//Set default controller
$dispatcher->setDefaultController($this->defaultController);
/**
* Get Event Manager
*
* @var \Phalcon\Events\Manager $eventsManager
*/
$eventsManager = $di->getShared('eventsManager');
//Attach acl in dispatcher
$eventsManager->attach('dispatch', $di->get('acl'));
//Set event manager
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
});
//Register the view component
$di->set('view', function () use($di, &$module) {
//Create Phalcon\Mvc\View
$view = new ZView();
$template = new ZTemplate($this->module);
//Attach event
$eventsManager = $di->getShared('eventsManager');
if (method_exists($eventsManager, 'attach')) {
$eventsManager->attach('view:beforeRender', $template);
$eventsManager->attach('view:afterRender', $template);
$eventsManager->attach('view:beforeRenderView', $template);
} else {
die(__FILE__ . ' Error: ZCMS cannot render template');
}
//Set view Event
$view->setEventsManager($eventsManager);
//Set view dir
$view->setViewsDir(APP_DIR . '/backend/' . $module . '/views/');
//Register engines
$view->registerEngines(['.volt' => function ($view, $di) {
$volt = new Volt($view, $di);
$volt->setOptions(['compiledPath' => function ($templatePath) {
$templatePath = strstr($templatePath, '/app');
$dirName = dirname($templatePath);
if (!is_dir(ROOT_PATH . '/cache/volt' . $dirName)) {
mkdir(ROOT_PATH . '/cache/volt' . $dirName, 0755, TRUE);
}
return ROOT_PATH . '/cache/volt' . $dirName . '/' . basename($templatePath, '.volt') . '.php';
}, 'compileAlways' => method_exists($di, 'get') ? (bool) $di->get('config')->backendTemplate->compileTemplate : false]);
$compiler = $volt->getCompiler();
$compiler->addFunction('get_sidebar', 'get_sidebar');
$compiler->addFunction('__', '__');
$compiler->addFunction('strtotime', 'strtotime');
$compiler->addFunction('human_timing', 'human_timing');
$compiler->addFunction('moneyFormat', 'moneyFormat');
$compiler->addFunction('number_format', 'number_format');
$compiler->addFunction('change_date_format', 'change_date_format');
$compiler->addFunction('in_array', 'in_array');
return $volt;
}]);
return $view;
}, true);
}