【发布时间】:2016-03-01 07:19:40
【问题描述】:
我在路由中遇到了一些奇怪的结果。
PDNController.pm中的参考代码
my $r = $self->routes;
my $auth = $r->under('/' => sub {
my $self = shift ;
$self->redirect_to('/login') and return undef unless ($self->is_user_authenticated);
return 1;
});
$r->get('/login')->to('login#index');
$r->post('/login')->to('login#auth');
$r->get('/logout')->to('login#logout');
$auth->get('/')->to('index#index');
$auth->get('/vlan')->to('vlan#index');
$auth->get('/api/vlan/add')->to('vlan#add');
PDNController/Controller/VLAN.pm中的参考代码
package PDNController::Controller::VLAN;
use Mojo::Base 'Mojolicious::Controller';
sub index {
my $self = shift;
$self->render();
}
sub add {
my $self = shift;
my %h;
$h{error} = '';
$self->res->headers->add( 'Access-Control-Allow-Origin' => '*' );
$self->render(json => {%h}});
}
1;
除了 /api/vlan/add 之外,此示例中的所有路由都可以正常工作,但最后我有一个错误
[Tue Mar 1 16:54:02 2016] [debug] GET "/api/vlan/add"
[Tue Mar 1 16:54:02 2016] [debug] Routing to a callback
[Tue Mar 1 16:54:02 2016] [debug] Controller "PDNController::Vlan" does not exist
[Tue Mar 1 16:54:02 2016] [debug] Template "vlan/add.html.ep" not found
[Tue Mar 1 16:54:02 2016] [debug] Template "not_found.development.html.ep" not found
[Tue Mar 1 16:54:02 2016] [debug] Template "not_found.html.ep" not found
[Tue Mar 1 16:54:02 2016] [debug] Rendering template "mojo/debug.html.ep"
[Tue Mar 1 16:54:02 2016] [debug] Rendering template "mojo/menubar.html.ep"
[Tue Mar 1 16:54:02 2016] [debug] 404 Not Found (0.052532s, 19.036/s)
为什么控制器名称为 PDNController::Vlan 而不是 PDNController::Controller::Vlan ?
Mojolicious 6.51
【问题讨论】:
-
很抱歉,但 /vlan 也不起作用。只有工作路线是 /, /login, /logout
-
我发现错误。控制器名称错误。 pm 文件以 VLAN 结尾,但必须是 Vlan :) Dummy, Dummy, Dummy :)
标签: perl mojolicious