有一个好主意是让BaseController并使所有控制器扩展该类吗? [英] Is a good idea have a BaseController and make all controllers extend that class?

查看:59
本文介绍了有一个好主意是让BaseController并使所有控制器扩展该类吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要所有控制器中的一些常见行为.有一个好主意是让BaseController并使所有控制器扩展该类吗?如果是这样,那么避免Fatal error: Class 'BaseController' not found错误的正确方法是什么.

I need some common behaviors in all controllers. Is a good idea have a BaseController and make all controllers extend that class? If so, What is the correct way to avoid the Fatal error: Class 'BaseController' not found error.

推荐答案

这肯定是一种常见的方法.

It's certainly a common approach.

但是ZF项目负责人Matthew Weier O'Phinney的文章解释动作帮助者提供相同的好处和更大的灵活性.

But an article by ZF project lead Matthew Weier O'Phinney explains how action-helpers can provide the same benefits with more flexibility.

尤其是,常见的基本控制器通常成为多个但并非全部控制器中使用的功能的垃圾场,因此变得过分杀伤力.动作助手是一种懒惰的替代方案,可以在需要的时间和地点精确地调用功能.

In particular, a common base controller often becomes a dumping ground for functionality that is used in multiple-but-not-all controllers, so it become overkill. Action-helpers are kind of a lazy-load alternative, invoking functionality precisely when and where you need it.

此外,动作帮助程序派发钩子-init()preDispatch()postDispatch()-允许您在每个控制器的基础上自动执行类似插件的功能.

Also, the action-helper dispatch hooks - init(), preDispatch() and postDispatch() - allow you to automate plugin-like functionality on a per-controller basis.

我去帮忙.但是,与大多数事情一样,YMMV. ;-)

I'd go action-helpers. But as with most things, YMMV. ;-)

这篇关于有一个好主意是让BaseController并使所有控制器扩展该类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆