我为页面主页创建自定义控制器。
控制器:
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 }
但我的控制器的网址会重定向到控制器sonata.page.page_service_manager:execute
路线:" page_slug"
答案 0 :(得分:0)
我找到了一个解决方案,但我不知道这是不是一个好习惯。
我创建了我的客户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
它有效。