2012-10-16 28 views
0

我已经安装了Sonata MediaBundle来管理我网站上的媒体。一切工作正常,但现在我需要自定义MediaController的viewAction。我已经复制了原始MediaController并进行了更改。它坐在src/Application/Sonata/MediaBundle/Controller。我把它放在那里,因为该文件夹是我使用easy-extends扩展MediaBundle时创建的。我使用注解路由,所以我的路由文件的相关部分看起来是这样的:如何覆盖SonataMediaBundle中的MediaController并正确写入路由?

media: 
    resource: '@Application/Sonata/MediaBundle/Controller' 
    type:  annotation 
    prefix: /media 

我的控制器看起来是这样的:

/** 
* Log controller. 
* 
* @Route("/media") 
*/ 
class MediaController extends BaseMediaController { 
/** 
* @throws NotFoundHttpException 
* 
* @param string $id 
* @param string $format 
* 
* @return Response 
* 
* @Route("/view/{video_id}", name="media_view") 
* @Method("GET") 
* @Template() 
*/ 
public function viewAction($id, $format = 'reference') 
{ 
    $media = $this->getMedia($id); 

    if (!$media) { 
     throw new NotFoundHttpException(sprintf('unable to find the media with the id : %s', $id)); 
    } 

    if (!$this->get('sonata.media.pool')->getDownloadSecurity($media)->isGranted($media, $this->getRequest())) { 
     throw new AccessDeniedException(); 
    } 

    return $this->render('SonataMediaBundle:Media:view.html.twig', array(
     'media'  => $media, 
     'formats' => $this->get('sonata.media.pool')->getFormatNamesByContext($media->getContext()), 
     'format' => $format 
    )); 
} 
} 

没有变化,到目前为止,除了注释。当我尝试访问URL http://my-server /媒体/视图/ 4我得到这个错误:

Cannot load resource "@Application/Sonata/MediaBundle/Controller". Make sure the "Application/Sonata/MediaBundle/Controller" bundle is correctly registered and loaded in the application kernel class. 
500 Internal Server Error - FileLoaderLoadException 

束装在AppKernel.php:

new Application\Sonata\UserBundle\ApplicationSonataUserBundle(), 

的什么问题的任何想法这里?我已经测试了写这条路线的各种方式,但没有任何改变。有没有更好的方法来覆盖MediaCOntroller? 在此先感谢。

回答

0

终于我知道发生了什么事。由于重构操作,导入路由的_main路由形成了app/config下的routing.yml文件,并且尝试导入当前不存在的media.yml文件。 由于PHPStorm具有本地历史功能,我发现它。 感谢大家看了这个问题。