本文整理汇总了PHP中Symfony\Component\Routing\Route::addOptions方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::addOptions方法的具体用法?PHP Route::addOptions怎么用?PHP Route::addOptions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\Route
的用法示例。
在下文中一共展示了Route::addOptions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
public function load($resource, $type = null)
{
if (true === $this->loaded) {
throw new \RuntimeException('Do not add this loader twice');
}
$routes = new RouteCollection();
$contextConfigLoader = $this->contextConfigLoader;
foreach ($contextConfigLoader->getRouting() as $routing) {
foreach ($routing as $id => $info) {
if (array_key_exists('pattern', $info)) {
$route = new Route($info['pattern']);
// merge options and defaults
if (array_key_exists('defaults', $info)) {
$route->addDefaults($info['defaults']);
}
if (array_key_exists('options', $info)) {
$route->addOptions($info['options']);
}
if (array_key_exists('requirements', $info)) {
$route->addRequirements($info['requirements']);
}
}
$routes->add($id, $route);
}
}
return $routes;
}
示例2: load
public function load($resource, $type = null)
{
$collection = new RouteCollection();
//load static routes
$importedRoutes = $this->import('@AppBundle/Resources/config/static-routing.yml', 'yaml');
$collection->addCollection($importedRoutes);
//load dynamic routes from database
$pages = $this->doctrine->getRepository('DataBundle:Page')->findBy(['active' => true], ['ordering' => 'asc']);
$importedRoutes = new RouteCollection();
//add default page if no pages are defined
if (count($pages) == 0) {
$route = new Route('/', ['_controller' => 'AppBundle:Page:defaultIndex']);
$importedRoutes->add('index', $route);
}
foreach ($pages as $page) {
$route = new Route('/' . $page->getSlug(), ['_controller' => 'AppBundle:Page:page']);
//todo: make slug conversion safe
if ($page->getIsIndex()) {
$name = 'index';
} else {
$name = str_replace('/', '', strtolower(trim($page->getTitle())));
}
$importedRoutes->add($name, $route);
//generate blog post url for tag
if ($page->getIsBlogTag() && !is_null($page->getTag())) {
$route = new Route('/' . trim($page->getSlug()) . '/post/{slug}', ['_controller' => 'AppBundle:Page:post']);
$route->addOptions(['post_from' => 'tag']);
$name = str_replace('/', '', strtolower(trim($page->getTitle())) . '_post');
$importedRoutes->add($name, $route);
}
//generate blog post url for blog
if ($page->getIsBlog() && !is_null($page->getBlog())) {
$route = new Route('/' . trim($page->getSlug()) . '/post/{slug}', ['_controller' => 'AppBundle:Page:post']);
$route->addOptions(['post_from' => 'blog']);
$name = str_replace('/', '', strtolower(trim($page->getTitle())) . '_post');
$importedRoutes->add($name, $route);
}
}
$collection->addCollection($importedRoutes);
return $collection;
}