【发布时间】:2012-10-16 02:09:01
【问题描述】:
我已安装 Sonata MediaBundle 来管理我网站中的媒体。一切正常,但现在我需要自定义 MediaController 的 viewAction。我已经复制了原始的 MediaController 并对其进行了更改。它的座位在src/Application/Sonata/MediaBundle/Controller。我把它放在那里是因为该文件夹是在我使用easy-extends 扩展 MediaBundle 时创建的。我正在为路由使用注释,所以我的路由文件的相关部分如下所示:
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/media/view/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
bundle 加载到 AppKernel.php 中:
new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
知道这里有什么问题吗?我已经测试了编写路线的各种方式,但没有任何改变。有没有更好的方法来覆盖 MediaCONtroller? 提前致谢。
【问题讨论】:
标签: symfony routes overriding bundle media