本文整理汇总了PHP中Phalcon\Mvc\Dispatcher::setModuleName方法的典型用法代码示例。如果您正苦于以下问题:PHP Dispatcher::setModuleName方法的具体用法?PHP Dispatcher::setModuleName怎么用?PHP Dispatcher::setModuleName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Mvc\Dispatcher
的用法示例。
在下文中一共展示了Dispatcher::setModuleName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: registerServices
/**
* Register services
*
* @param DiInterface $di
*/
public function registerServices(DiInterface $di)
{
$module = $this->module;
$baseControllers = $this->baseControllers;
//Registering a dispatcher
$di->set('dispatcher', function () use($di, &$module, &$baseControllers) {
/**
* @var \Phalcon\Events\ManagerInterface $eventsManager
*/
$eventsManager = $di->getShared('eventsManager');
$eventsManager->attach("dispatch:beforeException", function ($event, $dispatcher, $exception) {
/**
* @var Dispatcher $dispatcher
* @var \Phalcon\Mvc\Dispatcher\Exception $exception
*/
switch ($exception->getCode()) {
case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
$dispatcher->forward(['module' => 'index', 'controller' => 'error', 'action' => 'notFound404']);
return false;
}
return true;
});
$dispatcher = new Dispatcher();
//Set default namespace to this module
$dispatcher->setDefaultNamespace($baseControllers);
$dispatcher->setEventsManager($eventsManager);
$dispatcher->setModuleName($module);
return $dispatcher;
});
//Registering the view component
$di->set('view', function () use($di, &$module) {
$view = new View();
$view->setViewsDir(APP_DIR . '/frontend/' . $module . '/views/');
/**
* @var \Phalcon\Events\Manager $eventsManager
*/
$eventsManager = $di->getShared('eventsManager');
$eventsManager->attach('view:beforeRender', new ZFrontTemplate($this->module));
$eventsManager->attach('view:afterRender', new ZFrontTemplate($this->module));
//Set view Event
$view->setEventsManager($eventsManager);
$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')->frontendTemplate->compileTemplate : false, 'stat' => false]);
$compiler = $volt->getCompiler();
$compiler->addFunction('get_sidebar', 'get_sidebar');
$compiler->addFunction('__', '__');
$compiler->addFilter('t', function ($resolvedArgs) {
return '__(' . $resolvedArgs . ')';
});
$compiler->addFunction('strtotime', 'strtotime');
$compiler->addFunction('human_timing', 'human_timing');
$compiler->addFunction('moneyFormat', 'moneyFormat');
$compiler->addFunction('number_format', 'number_format');
$compiler->addFunction('zcms_header', 'zcms_header');
$compiler->addFunction('zcms_header_prefix', 'zcms_header_prefix');
$compiler->addFunction('change_date_format', 'change_date_format');
$compiler->addFunction('in_array', 'in_array');
return $volt;
}]);
return $view;
});
}