我为主页创建了自定义控制器。
控制器:
class FrontPageController extends Controller
{
public function homeAction()
{
return $this->render('FrontPageBundle:Page:home.html.twig');
}
}
routing.yml
front_page_home:
path: /
defaults: { _controller: FrontPageBundle:FrontPage:home }
但是我的控制器的url重定向到控制器sonata.page.page_service_manager:execute
路线:"page_slug"
我找到了一个解决方案,但我不知道这是否是一个好的做法。
我创建了我的客户RoutePageGenerator
类,并编辑了将更改到主页的路由的类。像这样:
// Iterate over declared routes from the routing mechanism
foreach ($this->router->getRouteCollection()->all() as $name => $route) {
if($route->getPath() === "/")
{
$name = trim($name);
$root = $this->pageManager->create(array(
'routeName' => $name,
'name' => $name,
'url' => $route->getPath(),
'site' => $site,
'requestMethod' => isset($requirements['_method']) ? $requirements['_method'] : 'GET|POST|HEAD|DELETE|PUT',
'slug' => '/',
));
}
我删除这部分代码:
$root = $this->pageManager->getPageByUrl($site, '/');
// no root url for the given website, create one
if (!$root) {
$root = $this->pageManager->create(array(
'routeName' => PageInterface::PAGE_ROUTE_CMS_NAME,
'name' => 'Homepage',
'url' => '/',
'site' => $site,
'requestMethod' => isset($requirements['_method']) ? $requirements['_method'] : 'GET|POST|HEAD|DELETE|PUT',
'slug' => '/',
));
$this->pageManager->save($root);
}
我创建我的客户UpdateCoreRoutesCommand和我调用我的RoutePageGenerator:
请执行php app/console sonata:page:create-snapshots --site=1
命令