我找到了解決方案,但我不知道這是否是好的做法。
我創建我的客戶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
和它的作品。