催化剂控制器问题

发布于 2024-12-14 15:26:31 字数 126 浏览 4 评论 0原文

我刚刚在我的第一个大型项目中使用了催化剂,我想知道我是否按照预期的方式使用了催化剂。

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

每个 url 有一个控制器是最佳实践还是应该考虑分组?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小猫一只 2024-12-21 15:26:32

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

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

但是,一旦您开始拥有更长的 URL,例如 localhost:3000/foo/bar/baz/quux,其中 baz 和 quux 是 bar 的参数,您将看到分离出包含名为“bar”的操作(子)的 Foo.pm 的好处。 (那是在我们享受连锁操作的乐趣之前......)

尽管有办法 你可以实现与 Rails 风格路由表相当的功能,但通常认为这不是一个好主意。 没有路由表是 Catalyst 相对于其他框架的固有特性/优势。

催化剂权威指南。如果你没有这本书,你应该拥有。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文