Commits

Allan Freitas committed 0033217

blog de exemplo em hmvc

Comments (0)

Files changed (7)

app/hmvc/kblog/ServiceProvider.php

+<?php namespace App\Hmvc\Kblog;
+ 
+class ServiceProvider extends \App\Hmvc\ServiceProvider {
+ 
+    public function register()
+    {
+        parent::register('kblog');
+    }
+ 
+    public function boot()
+    {
+        parent::boot('kblog');
+    }
+ 
+}

app/hmvc/kblog/config/meuconfig.php

+<?php
+
+return array(
+	'titulo' => 'Meu Blog HMVC',
+	'posts' => array(
+		array(
+			'slug' => 'como-instalar-laravel-4',
+			'titulo' => 'Como Instalar Laravel 4'
+		),
+		array(
+			'slug' => 'composer-openssl-error',
+			'titulo' => 'Composer Openssl Error'
+		)
+	),
+);

app/hmvc/kblog/controllers/HomeController.php

+<?php
+
+namespace App\Hmvc\Kblog\Controllers;
+
+use App\Hmvc\Kblog\Models\Post;
+
+class HomeController extends \BaseController {
+
+	public function index()
+	{
+		$posts = Post::all();
+
+		return \View::make('kblog::index')
+			->with('titulo_do_blog',\Config::get('kblog::meuconfig.titulo'))
+			->with('posts',$posts);
+	}
+
+	public function post($slug)
+	{
+		return \View::make('kblog::post')
+			->with('titulo_do_blog',\Config::get('kblog::meuconfig.titulo'))
+			->with('slug',$slug);
+	}
+
+}

app/hmvc/kblog/models/Post.php

+<?php
+
+namespace App\Hmvc\Kblog\Models;
+
+//poderia extender do Eloquent
+//mas é só um exemplo seria "\Eloquent"
+class Post extends \stdClass{
+
+	public static function all()
+	{
+		return \Config::get('kblog::meuconfig.posts');
+	}
+}

app/hmvc/kblog/routes.php

+<?php
+
+Route::get('blog/{slug}',array('as'=>'kblog_post_view',
+	'uses' => 'App\Hmvc\Kblog\Controllers\HomeController@post'));
+
+Route::get('blog', 'App\Hmvc\Kblog\Controllers\HomeController@index');

app/hmvc/kblog/views/index.blade.php

+
+<h1>Home - Listagem | {{$titulo_do_blog}}</h1>
+
+<ul>
+@foreach($posts as $post)
+	<li><a href="{{URL::route('kblog_post_view',$post['slug'])}}">{{$post['titulo']}}</a></li>
+@endforeach
+</ul>

app/hmvc/kblog/views/post.blade.php

+
+<h1>{{$slug}} | {{$titulo_do_blog}}</h1>