Reputation: 441
I will explain my issue with the code:
first my app (ls -R):
/Kantine
Controllers kantine.conf kantine.pl Kantine.pm templates
Kantine/Controllers: Restaurant.pm Sandwich.pm
Kantine/templates: cantine.html.ep
I launch it under hypnotoad with the command "hypnotoad kantine.pl".
Everything is fine
Kantine/kantine.pm :
package Kantine;
use strict;
use warnings;
use Mojo::Base 'Mojolicious';
sub startup
{
my $self = shift;
my $config = $self->plugin('Config');
my $r = $self->routes;
$r->get('/restaurant')->to('restaurant#loadData');
$r->get('/sandwich')->to('sandwich#loadData');
$r->get('/test')->to(template => 'cantine');
}
1;
Kantine/Controllers/Restaurant :
package Controllers::Restaurant;
use strict;
use warnings;
use Mojo::Base 'Mojolicious::Controller';
sub loadData
{
my $self = shift;
$self->render('cantine');
}
1;
"curl http://127.0.0.1:3000/test" works fine (got a blank page) but "curl http://127.0.0.1:3000/restaurant" doesn't (got page not found). And I don't unerstand why! If you see what is wrong..
Thx!
Upvotes: 0
Views: 112
Reputation: 343
I'm pretty sure that all the places you have used Controllers
should instead be Controller
(singular). The /test
route works because Mojolicious can find the template in templates
, however it doesn't look in Controllers
so it can't find Controllers::Restaurant
.
Upvotes: 1