#!/usr/local/bin/perl
use warnings;
use 5.014;
use Mojolicious::Lite;
use DBI;
# ...
get '/choose' => sub {
my $self = shift;
my $lastname = $self->param( 'lastname' );
my $sth = $dbh->prepare( "SELECT id, firstname, birthday FROM $table WHERE lastname == ?" );
$sth->execute( $lastname );
my @rows;
while ( my $row = $sth->fetchrow_hashref ) {
push @rows, { id => $row->{id}, firstname => $row->{firstname}, lastname => $lastname, birthday => $row->{birthday} };
}
if ( not @rows ) {
$self->redirect_to( 'new_entry' );
} elsif ( @rows == 1 ) {
my $id = $rows[0]{id};
$self->redirect_to( "/show_address?id=$id" ); # show_address needs parameter "id"
} else {
$self->stash( rows => \@rows );
$self->render( 'choose' );
}
};
# ...
When I use redirect_to
, is there another way to pass a parameter than writing it directly in the url ("/show_address?id=$id")?