Last active
December 17, 2015 10:49
-
-
Save baniol/5597766 to your computer and use it in GitHub Desktop.
example laravel controller & view (layout);
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>{{ $title }}</title> | |
</head> | |
<body> | |
{{ $content }} | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment