2015-08-17 72 views
0

我爲頁面創建自定義控制器。自定義主頁奏鳴曲頁面

控制器:

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」

回答

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 和它的作品。