催化剂控制器问题 [英] Catalyst Controller Questions

查看:65
本文介绍了催化剂控制器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在第一个大型项目中使用了催化剂,但我想知道是否以应有的方式使用催化剂.

I just used catalyst for my first large project and I was left wondering if I used catalyst in the way it was meant to be used.

我有Root.pm,并且在该文件中放置了多个URL处理程序.

I have Root.pm and inside of that file I put multiple url handlers.

最佳做法是每个网址有一个控制器,还是应该考虑分组?

Is it a best practice to have one controller per url or should a grouping be considered?

推荐答案

Catalyst的优点之一是它的灵活性.您可以执行此操作,但是最适合您的应用程序.

One of the beauties of Catalyst is its flexibility. You can do this however it best suits your application.

如果仅支持少数几个URL,那么将它们全部放入Root.pm并没有本质上的错误.特别是如果没有深度,即localhost:3000/foo和localhost:3000/bar

If you only have a handful of URLs you support, then there's nothing intrinsically wrong with putting them all in Root.pm. Particularly if there's no depth, ie localhost:3000/foo and localhost:3000/bar

但是,一旦您开始拥有更长的URL,例如localhost:3000/foo/bar/baz/quux,其中baz和quux是bar的参数,您将看到将Foo.pm分离出来的好处.包含一个称为栏"的操作(子). (那是在我们陷入连锁行动之乐之前……)

However, as soon as you start to have longer URLs such as localhost:3000/foo/bar/baz/quux where baz and quux are arguments to bar, you'll see the benefit of separating out a Foo.pm that contains an action (sub) called 'bar'. (And that's before we get into the joys of Chained Actions...)

尽管有很多方法,您可以实现与Rails样式路由表等效的方法,这通常不被认为是一个好主意. 具有路由表是Catalyst与其他框架相比的固有功能/优势.

Although there are ways that you can achieve the equivalent of a Rails style routing table, it's not generally considered to be a good idea. Not having a routes table is an intrinsic feature/benefit of Catalyst over other frameworks.

权威的催化剂指南.如果您没有这本书,那么应该.

There's a good discussion of this on pages 13-14 of The Definitive Guide to Catalyst. If you don't have this book, you should.

这篇关于催化剂控制器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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