Snippets

Brian Medley Multiple Controllers with Mojolicious

Created by Brian Medley
package MultiController::Controller::Dashboard;

use Mojo::Base 'Mojolicious::Controller';

sub show {
    my $c = shift;
    
    $c->render(text => "Weeee");
}

1;
package MultiController::Controller::Index;

use Mojo::Base 'Mojolicious::Controller';

sub slash {
    my $c = shift;
    
    if ($c->param("login")) {
        return($c->redirect_to("/dashboard"));
    }
    
    $c->render(text => "Hello");
}

1;
package MultiController;

use Mojo::Base 'Mojolicious';

sub startup {
    my $self = shift;
    
    my $r = $self->routes;
    
    $r->get('/')->to(controller => "Index", action => "slash");

    $r->get('/dashboard')->to(controller => "Dashboard", action => "show");
}

1;

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.