Thread Mojolicious: bedingtes "self->render"
(10 answers)
Opened by Kuerbis at 2011-08-10 10:56
Meine vorläufige Finalverison:
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 get '/zwei' => sub { my $self = shift; my $nachname = $self->param( 'nachname' ); my $sth = $dbh->prepare( "SELECT vorname, steuernummer FROM $table WHERE nachname == ?" ); $sth->execute( $nachname ); my @rows; while ( my $row = $sth->fetchrow_hashref ) { push @rows, { vorname => $row->{vorname}, nachname => $nachname, steuernummer => $row->{steuernummer} }; } if ( not @rows ) { $self->redirect_to( 'eingabe' ); } elsif ( @rows == 1 ) { my $steuernummer = $rows[0]{steuernummer}; my $uri = URI->new( '/kontrolle' ); $uri->query_form( steuernummer => $steuernummer ); $self->redirect_to( $uri ); } else { $self->stash( rows => \@rows ); $self->render( 'zwei' ); } }; |