dt246813579 2014-06-30 08:55 采纳率: 0%
浏览 30

从symfony2中的自定义控制器类扩展所有控制器类

Like in Codeigniter we do have 'core' folder where we can define our own controller like 'MY_Controller' and can be used to extend all the class to extend from this controller is there any possibility to do so in Symfony2.

In symfony I want to create class 'MY_Controller' which extends from the base class 'Controller', and I want all the classes in the controllers to extend from MY_Controller' class.

Thanks in Advance...

  • 写回答

2条回答 默认 最新

  • dongshi1868 2014-06-30 09:07
    关注
    • First, don't name the class using underscores as in PSR-0 each underscore char is converted to a directory separator, when used in class name.
    • Second, put your controllers to <bundledir>/Controller/
    • Third, name your controller something like BaseController and extend all other controllers from it.
    • Fourth, think of using dependency injection rather than coupling functionality in a base controller.
    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害