Hello,

I just started playing with mojolicious and i am trying to create a CRUD 
app for the learning purpose
the code i'll show is working fine but i suspect i am doing things in an 
non efficient way, plus, Morbo complain about "number od element in 
anonimous hash":

So here is the code i am using:

...

helper dbi => sub {
    my $dbi = DBIx::Custom->connect(dsn => "dbi:SQLite:dbname=database.db",
                                    option => {sqlite_unicode => 1});
};

get '/test' => sub {
  my $c = shift;
  my $result = $c->dbi->select(table => 'table');
  $result = $result->all;
  $c->stash(people => $result);
  $c->render(template => 'listing');
};

@@  listing.html.ep
% layout 'testing', title 'Listing';
...
    <table class="table table-striped">
     ...
        <tbody>
              % foreach my $user (@{$people}) {
                  <tr>
                    <td>
                        %= $user->{name}
                    </td>
                    <td>
                        %= $user->{town}
                    </td>
                    <td>
                        %= $user->{structure}
                    </td>
            % }
          </tr>
        </tbody>
    </table>

@@ layouts/testing.html.ep
...

the message that morbo displayed in the terminal is:

Odd number of elements in anonymous hash at /home/.../Mojo/Util.pm line 434.

Why this message?

In the documentation of the DBIx::Custom the code was:

use Mojolicious::Lite
    use DBIx::Custom;

    app->attr(
        dbi => sub {
            my $dbi = DBIx::Custom->connect(dsn => "...");
            return $dbi;
        }
    );

    get '/foo' => sub {
        my $self = shift;
        $self->dbi->select(...);
        $self->render;
    };

    app->start;


It's not working for me and if someone could explain me, that will be great.

I noticed this code is not using stash explicitly! so i suspect that i am 
doing something non optimal in my code.

I used stash because i don't know how to access data passed to templates 
another way. if there is another way to do it, let me know, please

thanks a lot.

Best regards
Zakaria

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to