本文整理匯總了PHP中Drupal\Core\Routing\RouteProviderInterface::preLoadRoutes方法的典型用法代碼示例。如果您正苦於以下問題:PHP RouteProviderInterface::preLoadRoutes方法的具體用法?PHP RouteProviderInterface::preLoadRoutes怎麽用?PHP RouteProviderInterface::preLoadRoutes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Drupal\Core\Routing\RouteProviderInterface
的用法示例。
在下文中一共展示了RouteProviderInterface::preLoadRoutes方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: onRequest
/**
* Loads all non-admin routes right before the actual page is rendered.
*
* @param \Symfony\Component\HttpKernel\Event\KernelEvent $event
* The event to process.
*/
public function onRequest(KernelEvent $event)
{
// Only preload on normal HTML pages, as they will display menu links.
if ($this->routeProvider instanceof PreloadableRouteProviderInterface && $event->getRequest()->getRequestFormat() == 'html') {
if ($routes = $this->state->get('routing.non_admin_routes', [])) {
// Preload all the non-admin routes at once.
$this->routeProvider->preLoadRoutes($routes);
}
}
}
示例2: onRequest
/**
* Loads all non-admin routes right before the actual page is rendered.
*
* @param \Symfony\Component\HttpKernel\Event\KernelEvent $event
* The event to process.
*/
public function onRequest(KernelEvent $event)
{
// Only preload on normal HTML pages, as they will display menu links.
if ($this->routeProvider instanceof PreloadableRouteProviderInterface && $event->getRequest()->getRequestFormat() == 'html') {
// Ensure that the state query is cached to skip the database query, if
// possible.
$key = 'routing.non_admin_routes';
if ($cache = $this->cache->get($key)) {
$routes = $cache->data;
} else {
$routes = $this->state->get($key, []);
$this->cache->set($key, $routes, Cache::PERMANENT, ['routes']);
}
if ($routes) {
// Preload all the non-admin routes at once.
$this->routeProvider->preLoadRoutes($routes);
}
}
}