diff --git a/application/bootstrap.php b/application/bootstrap.php index 6ea5d7c..b3efc5e 100644 --- a/application/bootstrap.php +++ b/application/bootstrap.php @@ -120,8 +120,13 @@ * defaults for the URI. */ -// FOR PAGINATION INT POSTAGENS -Route::set('postagens', '') +// FOR PAGINATION +Route::set('home', 'home') + ->defaults(array( + 'controller' => 'home', + 'action' => 'index', + )); +Route::set('postagens', 'postagens') ->defaults(array( 'controller' => 'postagens', 'action' => 'index', diff --git a/application/classes/controller/home.php b/application/classes/controller/home.php index 12b0ea7..8dea131 100644 --- a/application/classes/controller/home.php +++ b/application/classes/controller/home.php @@ -2,10 +2,33 @@ class Controller_Home extends Controller_ApplicationBlog { - public function action_index(){ + public function action_index(){ - $content = View::factory('site/home/page'); + $posts = ORM::factory('post'); + $count_all = $posts->count_all(); + + /* Pagination */ + $pagination = Pagination::factory(array( + 'current_page' => array('source' => 'query_string', 'key' => 'page'), + 'total_items' => $count_all, + 'items_per_page' => 4, + 'view' => 'pagination/basic', + 'auto_hide' => TRUE, + 'first_page_in_url' => TRUE, + )); + + $pagination_links = $pagination->render(); + + $posts = $posts + ->limit($pagination->items_per_page) + ->offset($pagination->offset) + ->order_by('id', 'DESC') + ->find_all(); + + $content = View::factory('site/home/page') + ->bind('posts', $posts) + ->bind('pagination_links', $pagination_links); $this->template->content = $content; } diff --git a/application/classes/controller/postagens.php b/application/classes/controller/postagens.php index 07c7e1b..bf5e635 100644 --- a/application/classes/controller/postagens.php +++ b/application/classes/controller/postagens.php @@ -14,7 +14,7 @@ public function action_index(){ $pagination = Pagination::factory(array( 'current_page' => array('source' => 'query_string', 'key' => 'page'), 'total_items' => $count_all, - 'items_per_page' => 2, + 'items_per_page' => 3, 'view' => 'pagination/basic', 'auto_hide' => TRUE, 'first_page_in_url' => TRUE, @@ -25,6 +25,7 @@ public function action_index(){ $posts = $posts ->limit($pagination->items_per_page) ->offset($pagination->offset) + ->order_by('id', 'DESC') ->find_all(); $content = View::factory('site/postagens/page') @@ -42,7 +43,7 @@ public function action_novo(){ # apenas para inicializar $post = array(); - $content = View::factory('site/postagens/novo') + $content = View::factory('site/postagens/form') ->bind('action', $action) ->bind('post', $post); @@ -73,6 +74,50 @@ public function action_novo(){ } + public function action_editar(){ + + # pega a action que está sendo utilizada + $action = $this->request->action(); + + # get the id to where condition + $id = (string) Arr::get($_GET, 'id'); + + $posts = ORM::factory('post'); + + $post = $posts + ->where('id', '=', $id) + ->find(); + + $content = View::factory('site/postagens/form') + ->bind('action', $action) + ->bind('post', $post); + + $this->template->content = $content; + + if ($_POST && isset($_POST['salvar'])) { + + $time_now = new DateTime(); + + $post = ORM::factory('post', $id); + + $post->titulo = (string) Arr::get($_POST, 'titulo'); + $post->chamada = (string) Arr::get($_POST, 'chamada'); + $post->texto = (string) Arr::get($_POST, 'texto'); + + $post->update(); + + $redirect = URL::site($this->_redirect); + $this->request->redirect($redirect); + } + + + if($_POST && isset($_POST['cancelar'])){ + + $redirect = URL::site($this->_redirect); + $this->request->redirect($redirect); + } + } + public function action_deletar(){ $id = (string) Arr::get($_GET, 'id'); diff --git a/application/views/site/home/page.php b/application/views/site/home/page.php index 657808e..d13a7b0 100644 --- a/application/views/site/home/page.php +++ b/application/views/site/home/page.php @@ -1,30 +1,41 @@
-
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
-
22 de julho, por Zé - 12 comentários
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec commodo, nulla varius imperdiet molestie, ligula dui lobortis lacus, ut elementum purus libero non odio. Suspendisse luctus libero sit amet sem dignissim vel mattis tellus bibendum. Pellentesque malesuada lacus sed neque rhoncus...
-
-
- -
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
-
22 de julho, por Zé - 12 comentários
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec commodo, nulla varius imperdiet molestie, ligula dui lobortis lacus, ut elementum purus libero non odio. Suspendisse luctus libero sit amet sem dignissim vel mattis tellus bibendum. Pellentesque malesuada lacus sed neque rhoncus...
-
-
- -
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
-
22 de julho, por Zé - 12 comentários
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec commodo, nulla varius imperdiet molestie, ligula dui lobortis lacus, ut elementum purus libero non odio. Suspendisse luctus libero sit amet sem dignissim vel mattis tellus bibendum. Pellentesque malesuada lacus sed neque rhoncus...
-
-
- - -
« 1 2 3 4 »
- + + + + + +
+
titulo; ?>
+
data_registro); + $data_registro = $data_registro->format('d/m/Y'); + + echo $data_registro . ' por Zé - 6 comentários' ; ?>
+
chamada ?>
+
+
+ + + + + + + +
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+
22 de julho, por Zé - 12 comentários
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec commodo, nulla varius imperdiet molestie, ligula dui lobortis lacus, ut elementum purus libero non odio. Suspendisse luctus libero sit amet sem dignissim vel mattis tellus bibendum. Pellentesque malesuada lacus sed neque rhoncus...
+
+
+ +
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+
22 de julho, por Zé - 12 comentários
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec commodo, nulla varius imperdiet molestie, ligula dui lobortis lacus, ut elementum purus libero non odio. Suspendisse luctus libero sit amet sem dignissim vel mattis tellus bibendum. Pellentesque malesuada lacus sed neque rhoncus...
+
+
+ +
- diff --git a/application/views/site/postagens/novo.php b/application/views/site/postagens/form.php similarity index 79% rename from application/views/site/postagens/novo.php rename to application/views/site/postagens/form.php index ddb3c38..327f3cb 100644 --- a/application/views/site/postagens/novo.php +++ b/application/views/site/postagens/form.php @@ -7,22 +7,26 @@

=== ===

+ + + +
- + titulo) ? $post->titulo : ''; ?> 'Titulo')); ?>:
'titulo', 'size' => '60')); ?>
- + chamada) ? $post->chamada : ''; ?> 'Chamada')); ?>:
'chamada' , 'rows' => 5, 'cols' => '60' )); ?>
- + texto) ? $post->texto : ''; ?> 'Texto')); ?>:
'texto' , 'rows' => 12, 'cols' => '60' )); ?>
diff --git a/bd_blog.sql b/bd_blog.sql index 0721ac0..8d9f89b 100644 --- a/bd_blog.sql +++ b/bd_blog.sql @@ -5,7 +5,7 @@ -- POSTS CREATE TABLE IF NOT EXISTS `posts`( `id` INT(8) NOT NULL AUTO_INCREMENT, -`titulo` VARCHAR(30) NOT NULL, +`titulo` VARCHAR(200) NOT NULL, `chamada` TEXT NOT NULL, `texto` TEXT NOT NULL, `data_registro` DATETIME, diff --git a/media/css/style.css b/media/css/style.css index fed035c..d918c4c 100644 --- a/media/css/style.css +++ b/media/css/style.css @@ -82,11 +82,11 @@ select:focus { outline: none; } /*==MENU==*/ -#menu nav { width:500px; height:30px; } -#menu nav ul li{ float: left; list-style: none; font-size: 11px; margin-right: 20px; } -#menu nav ul li a{ position: relative; color: #444; } -#menu nav ul li a:hover{ color: #999; } -#menu nav ul li a:active{ bottom: -2px;} +#menu nav { width:500px; height:30px; margin: 10px 0px; } +#menu nav ul li{ float: left; list-style: none; font-size: 11px; } +#menu nav ul li a{ position: relative; color: #444; padding: 8px 15px; background-color: #DDD; } +#menu nav ul li a:hover{ color: #666; background-color: #d6d6d6; } +#menu nav ul li a:active{ bottom: -3px; color: #888; background-color: #d4d4d4;} /*==posts==*/ @@ -103,7 +103,9 @@ select:focus { outline: none; } #listar_posts dl.post dd.mais a{ display: block; font-size: 22px; color: #999; padding: 0px 0px 2px 0px; } #listar_posts dl.post dd.mais a:hover{ color: #333; } -#listar_posts .paginacao { font-size: 22px; text-align: center; margin: 20px; } +#listar_posts .pagination .go_to{ font-size: 28px; color: #333; } +#listar_posts .pagination { font-size: 22px; text-align: center; color: #aaa; word-spacing: 10px; margin: 20px; } +#listar_posts .pagination a{ color: #333; } /*==SOBRE==*/ diff --git a/modules/pagination b/modules/pagination index d1c34df..a0535f0 160000 --- a/modules/pagination +++ b/modules/pagination @@ -1 +1 @@ -Subproject commit d1c34df4d64e63591793b73179ff21953071fd06 +Subproject commit a0535f019ab33d7e2323762d4acbf20f46dd588e