Catalyst Controller Questions

让人想犯罪 __ 提交于 2019-12-07 17:22:14

问题


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.

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?


回答1:


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

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

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...)

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.



来源:https://stackoverflow.com/questions/8067732/catalyst-controller-questions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!