如何使用 Config::General 在给定控制器中配置所有 Catalyst 操作?

发布于 2024-09-28 23:35:40 字数 819 浏览 4 评论 0原文

我想使用我的应用程序的配置文件配置控制器中的所有操作。根据 Catalyst::Controller 我可以在控制器本身中执行此操作:

__PACKAGE__->config(
    action => {
        '*' => { Chained => 'base', Args => 0  },
    },
 );

所以我在我的配置中尝试了此操作:

<controller Foo>
    <action "*">                                                                
        Chained base
        Args 0
    </action>
</controller>

但是我在启动时收到此错误:

Couldn't load class (MyApp) because: Action "*" is not available from 
controller MyApp::Controller::Foo at /usr/local/share/perl/5.10.1/Catalyst/
Controller.pm line 193

它在没有星号周围的引号的情况下执行相同的操作。我该怎么做?

I want to configure all the actions in my controller using my app's config file. According to Catalyst::Controller I can do this in the controller itself:

__PACKAGE__->config(
    action => {
        '*' => { Chained => 'base', Args => 0  },
    },
 );

So I tried this in my config:

<controller Foo>
    <action "*">                                                                
        Chained base
        Args 0
    </action>
</controller>

But I get this error on startup:

Couldn't load class (MyApp) because: Action "*" is not available from 
controller MyApp::Controller::Foo at /usr/local/share/perl/5.10.1/Catalyst/
Controller.pm line 193

It does the same without the quotes around the asterisk. How should I do this?

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

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

发布评论

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

评论(1

安穩 2024-10-05 23:35:40

Catalyst 权威指南中对此进行了介绍,

从该页面获取可下载的源代码,将其解压缩,转到第 7 章中的 DwarfChains 应用程序,然后将以下内容添加到 dwarfchains.conf:

 <Controller People>
 <action get_ready>
  PathPart nama
 </action>
 </Controller>

 <Controller People::Info>
 <action get_info_ready>
  PathPart siapa
 </action >
 <action create>
  PathPart lagi
 </action >
 <action delete>
  PathPart mengusir
 </action >
 </Controller>

这或多或少应该演示如何通过配置覆盖调度。

This is covered in The Definitive Guide to Catalyst

Grab the downloadable source from that page, unzip it, go to the DwarfChains application in chapter 7, then add the following to dwarfchains.conf:

 <Controller People>
 <action get_ready>
  PathPart nama
 </action>
 </Controller>

 <Controller People::Info>
 <action get_info_ready>
  PathPart siapa
 </action >
 <action create>
  PathPart lagi
 </action >
 <action delete>
  PathPart mengusir
 </action >
 </Controller>

That should more or less demonstrate how to override dispatch by configuration.

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