2014-12-13 44 views
1

我不能得到SeoBundle从我的照片如何设置SeoBundle并提取标题?

我在config.yml配置 “content_key” 称号提取

cmf_seo: 
    content_key: "mykey" 
    title: "%%content_title%%" 

我的实体实现TitleReadInterface

class Picture implements TitleReadInterface { 
    (...) 

    public function getSeoTitle() 
    { 
     return $this->title; 
    } 

    (...) 
} 

并在控制器我更新“mykey”属性:

public function viewAction(Request $request, $slug) { 
    (...) 

    $picture = $repository->findOneBySlug($slug); 

    $request->attributes->set('mykey', $picture); 

    (...) 

} 

最后,鉴于有:

{{ sonata_seo_title() }} 

但是页面的标题是“索纳塔计划” :( 有什么不对?

+0

真的吗?没有人有想法? – 2014-12-14 08:59:12

+0

在controller :: viewAction之前触发了Symfony \ Cmf \ Bundle \ SeoBundle \ EventListener \ ContentListener :: onKernelRequest(GetResponseEvent $ event),并且请求中没有“mykey”属性... – 2014-12-16 07:58:16

回答

2

最后我发现,如果你不使用DynamicRouter(就像我的情况那样),你必须以另一种方式提供内容对象,这个bundle对DynamicRouter更好。我的解决方案是从控制器手动触发SeoPresentation过程:

public function viewAction(Request $request, $slug) { 
    (...) 

    $picture = $repository->findOneBySlug($slug); 

    $seo = $this->get('cmf_seo.presentation'); 
    $seo->updateSeoPage($picture); 

    (...) 

}