frazap has asked for the wisdom of the Perl Monks concerning the following question:
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 areThe run.pl script isrun.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 Lib.pm module isuse strict; use warnings; use lib 'lib'; use Mojolicious::Commands; Mojolicious::Commands->start_app('Lib')
The Invtot.pm module connects to the database, it ispackage 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;
And the file that I placed under Invtot/Controller (also named Invtot.pm ....) ispackage 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;
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
How should I correct this ?Class "Lib::Invtot" is not a controller Template "invtot/post.html.ep" not found
frazap
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: First steps with Mojolicious
by Your Mother (Archbishop) on May 01, 2019 at 19:47 UTC | |
by frazap (Monk) on May 02, 2019 at 06:07 UTC | |
|
Re: First steps with Mojolicious
by frazap (Monk) on May 01, 2019 at 14:38 UTC |