让 CodeIgniter 默认使用_Controller 而不更改库?
我发现在为 CodeIgniter 开发时与类名有很多冲突。例如,我最近遇到这样的情况:我有一个 Checkout 控制器:
class Checkout extends Controller
{
// Contents
}
然后继续创建一个新的自定义库:
class Checkout
{
// Contents
}
这显然会引发错误。
我想要的是能够将我的控制器定义为
这样:
class Checkout_Controller extends Controller
{
// Contents
}
我希望 CodeIgniter 像任何其他控制器一样选择它。我还想在不更改任何核心库的情况下执行此操作,以便我可以更新它而无需一次又一次重新实现我的更改。
我知道你可以通过路由来做到这一点(这就是我到目前为止处理它的方式),但在我看来,这更像是一种黑客行为,而不是实际的解决方案。有没有办法强制 CodeIgniter 使用我想要的语法以及我需要的限制?
I'm finding I have lots of conflicts with class names when developing for CodeIgniter. For example, I recently had the situation where I had a Checkout controller:
class Checkout extends Controller
{
// Contents
}
And then went on to create a new custom library:
class Checkout
{
// Contents
}
Which would obviously throw an error.
What I want is to be able to define my controllers as <ControllerName>_Controller
so:
class Checkout_Controller extends Controller
{
// Contents
}
And I want CodeIgniter to pick this up as it would any other controller. I also want to do this without changing any of the core library so that I can update it without re-implementing my changes again and again.
I know you can do this with routing (and it's how I have been handling it so far) but this seems to me to be more like a hack than an actual solution. Is there a way to force CodeIgniter to use the syntax I want with the restrictions I need?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然本文总体上“磨练我的齿轮”,但它确实向您展示了如何为控制器添加 _Controller 后缀。
http://net.tutsplus.com/tutorials /php/6-codeigniter-hacks-for-the-masters/
While this article generally "grinds my gears" it does show you how to the _Controller suffix to your controllers.
http://net.tutsplus.com/tutorials/php/6-codeigniter-hacks-for-the-masters/