baniol
5/17/2013 - 8:32 AM

example laravel controller & view (layout);

example laravel controller & view (layout);

<html>
    <head>
        <title>{{ $title }}</title>
    </head>
    <body>
        {{ $content }}
    </body>
</html>
// taken from : http://forums.laravel.io/viewtopic.php?id=839
class Blog_Controller extends Controller
{

    public $layout = 'layouts.default';

    public function action_index()
    {

        $this->layout->title = "Blog";

        $this->layout->content = View::make( 'blog::index' )->with( 'posts', Post::published()->paginate() );

    }

    public function action_author( $user_id )
    {

        $user = User::find( $user_id );

        if( is_null( $user ) ) return Response::error( '404' );

        $posts = Post::published_by_author( $user_id )->paginate();

        $this->layout->title = "Blog | Viewing posts by $user->name";
        $this->layout->content = View::make( 'blog::author' )->with( 'user', $user )->with( 'posts', $posts );

    }
}