本文整理汇总了PHP中Phalcon\DiInterface::getResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP DiInterface::getResponse方法的具体用法?PHP DiInterface::getResponse怎么用?PHP DiInterface::getResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\DiInterface
的用法示例。
在下文中一共展示了DiInterface::getResponse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerServices
/**
* Register the services here to make them general
* or register in the ModuleDefinition to make them module-specific
*/
public function registerServices(DiInterface $di)
{
//Read configuration
$config = (include __DIR__ . "/config/config.php");
$configGlobal = $di->getConfig();
// The URL component is used to generate all kind of urls in the application
$di->set('url', function () use($config, $configGlobal) {
$url = new Url();
if (APPLICATION_ENV == 'production') {
$url->setStaticBaseUri($configGlobal->application->production->staticBaseUri);
} else {
$url->setStaticBaseUri($configGlobal->application->development->staticBaseUri);
}
$url->setBaseUri($config->application->baseUri);
return $url;
});
//Registering a dispatcher
$di->set('dispatcher', function () use($di) {
//Create/Get an EventManager
$eventsManager = new EventsManager();
//Attach a listener
$eventsManager->attach('dispatch', function ($event, $dispatcher, $exception) use($di) {
//controller or action doesn't exist
if ($event->getType() == 'beforeException') {
$message = $exception->getMessage();
$response = $di->getResponse();
switch ($exception->getCode()) {
case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
$response->redirect();
return false;
case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
$response->redirect('action-not-found?msg=' . $message);
return false;
case Dispatcher::EXCEPTION_CYCLIC_ROUTING:
$response->redirect('cyclic-routing?msg=' . $message);
return false;
}
}
});
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace("Phanbook\\Backend\\Controllers");
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
});
/**
* Setting up the view component
*/
$di->set('view', function () use($config) {
$view = new View();
$view->setViewsDir($config->application->viewsDir);
$view->disableLevel([View::LEVEL_MAIN_LAYOUT => true, View::LEVEL_LAYOUT => true]);
$view->registerEngines(['.volt' => 'volt']);
// Create an event manager
$eventsManager = new EventsManager();
// Attach a listener for type 'view'
$eventsManager->attach('view', function ($event, $view) {
if ($event->getType() == 'notFoundView') {
throw new \Exception('View not found!!! (' . $view->getActiveRenderPath() . ')');
}
});
// Bind the eventsManager to the view component
$view->setEventsManager($eventsManager);
return $view;
});
$configMenu = (include __DIR__ . "/config/config.menu.php");
$di->setShared('menuStruct', function () use($configMenu) {
// if structure received from db table instead getting from $config
// we need to store it to cache for reducing db connections
$struct = $configMenu->get('menuStruct')->toArray();
return $struct;
});
}