I have two small web apps that I managed to create with Mojolicious::Lite separately. Now I'm trying to unite these pages in one bigger Mojolicious application.
The page's names are libmap, invtot and together they would create the Lib application, therefore the Lib.pm file.
My files and folders are
run.pl
lib.conf
templates
common_js.html.ep
invtot.html.ep
libmap.html.ep
layouts
default.html.ep
public
index.html
some .js files
lib
Lib.pm
Invtot.pm
Invtot
Controller
Invtot.pm
The run.pl script is
use strict;
use warnings;
use lib 'lib';
use Mojolicious::Commands;
Mojolicious::Commands->start_app('Lib')
The Lib.pm module is
package Lib;
use Mojo::Base 'Mojolicious';
# This method will run once at server start
sub startup {
my $self = shift;
# Load configuration from hash returned by config file
my $config = $self->plugin('Config');
# Configure the application
$self->secrets($config->{secrets});
# Router
my $r = $self->routes;
# Normal route to controller
$r->get('/')->to(controller => 'index');
$r->get('/libmap');
$r->get('/invtot');
$r->post('/invtot')->to(controller => 'Invtot', action=> 'post');
}
1;
The Invtot.pm module connects to the database, it is
package Invtot;
use Mojo::Base 'Mojolicious';
sub startup {
my $app = shift;
my $config = $app->config;
$app->log->debug("connecting...");
$app->plugin(
'Database',
{ dsn => 'dbi:mysql:host=mysql.unifr.ch:dbname=dokpe_i0
+1',
username => $config->{username},
password => $config->{password},
options => {
'pg_enable_utf8' => 1,
AutoCommit => 1,
PrintError => 0,
RaiseError => 1
},
helper => 'db',
}
);
}
1;
And the file that I placed under Invtot/Controller (also named Invtot.pm ....) is
package Invtot::Controller::Invtot;
use Mojo::Base 'Mojolicious::Controller';
sub post {
my $c = shift;
my $p = $c->req->body_params->to_hash;
#gets the form values
my $for_abo = $p->{'ccabo'} // '' eq 'ABO' ? 1 : 0;
my $reqVal = $p->{'ZLField'};
....
#build the sql string
$sql{$key} = format_sql( $reqVal, $p->{ZLMode}, $for_abo );
#get the values from the db
my $stm = $c->db->prepare_cached( $sql{$key} )
$stm->execute($toFind) or die $stm->errstr;
$c->stash( stm => $stm, for_abo => $for_abo );
}
#build the page with the db values
$c->render('invtot');
}
...
1;
The libmap page and the form from the invtot page are displayed correctly. However, the post is not run :
I got the error
Class "Lib::Invtot" is not a controller
Template "invtot/post.html.ep" not found
How should I correct this ?
frazap