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


In reply to First steps with Mojolicious by frazap

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.