/site/lib/MyApp.pm

package MyApp;
use Mojo::Base 'Mojolicious';
use Schema;

BEGIN {
$ENV{MOJO_MODE} = 'development';
$ENV{MOJO_LOG_LEVEL} = 'debug'; 
$ENV{MOJO_LOG_LEVEL} = 'error';
}

has schema => sub {
  return Schema->connect('dbi:SQLite:' . ($ENV{BLOG_DB} || 
'./dump/blog.db'));
};

sub startup {
  
my $self = shift;
  $self->helper(db => sub { $self->app->schema });
  
  # Router
  my $r = $self->routes;

  # Normal route to controller
  $r->get('/')->to('site#index');
  
  # Blog routes
  $r->get('/blog')->to('blog#index'); 
  $r->any('/save')->via('post')->to('blog#save');
  $r->any('/update')->via('post')->to('blog#update');
  $r->any('/delete')->via('post')->to('blog#delete');
  $r->get('/create')->to('blog#create');
  $r->any('/edit')->via('get')->to('blog#edit');
  
  $r->get('/blog/:id')->to('blog#show');
}

1;

/site/lib/MyApp/Controller/Blog.pm

package MyApp::Controller::Blog;
use Mojo::Base 'Mojolicious::Controller';
use Schema;

sub index {
    my $self = shift;
    my $posts = $self->db->resultset('Post');
    $self->render( posts => $posts );
}

sub save {
    my $self = shift;
    my ($title, $body, $tags) = @{$self->req->params->to_hash}{ 'title', 
'body', 'tags' };
    # Тут бы проверить переменные
    my $result = $self->db->resultset('Post')->create({
    title => '$title',
    post  => '$body',
    tags => '$tags'
    });
}

Thanks.

четверг, 21 мая 2015 г., 20:10:47 UTC+3 пользователь Rob Willett написал:
>
> Your schema looks OK, whats the rest of your code look like?
>
> Rob
>
>

-- 
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 http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to