diff --git a/application/bootstrap.php b/application/bootstrap.php index 1f31457..dcc0a8c 100644 --- a/application/bootstrap.php +++ b/application/bootstrap.php @@ -110,14 +110,18 @@ 'orm' => MODPATH.'orm', // Object Relationship Mapping // 'unittest' => MODPATH.'unittest', // Unit testing 'userguide' => MODPATH.'userguide', // User guide and API documentation + 'pagination' => MODPATH.'pagination', // Pagination for Kohana 3.2 )); /** * Set the routes. Each route must have a minimum of a name, a URI and a set of * defaults for the URI. */ + + Route::set('default', '((/(/)))') ->defaults(array( 'controller' => 'home', 'action' => 'index', )); + diff --git a/application/classes/controller/postagens.php b/application/classes/controller/postagens.php index 057b80e..07c7e1b 100644 --- a/application/classes/controller/postagens.php +++ b/application/classes/controller/postagens.php @@ -2,19 +2,44 @@ class Controller_Postagens extends Controller_ApplicationBlog { + protected $_redirect = "../postagens"; + public function action_index(){ + $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' => 2, + 'view' => 'pagination/basic', + 'auto_hide' => TRUE, + 'first_page_in_url' => TRUE, + )); + + $pagination_links = $pagination->render(); - $content = View::factory('site/postagens/page'); + $posts = $posts + ->limit($pagination->items_per_page) + ->offset($pagination->offset) + ->find_all(); + + $content = View::factory('site/postagens/page') + ->bind('posts', $posts) + ->bind('pagination_links', $pagination_links); $this->template->content = $content; } public function action_novo(){ + # pega a action que está sendo utilizada $action = $this->request->action(); + # apenas para inicializar $post = array(); $content = View::factory('site/postagens/novo') @@ -23,6 +48,40 @@ public function action_novo(){ $this->template->content = $content; + if ($_POST && isset($_POST['salvar'])) { + + $time_now = new DateTime(); + + $post = ORM::factory('post'); + + $post->titulo = (string) Arr::get($_POST, 'titulo'); + $post->chamada = (string) Arr::get($_POST, 'chamada'); + $post->texto = (string) Arr::get($_POST, 'texto'); + $post->data_registro = $time_now->format('Y-m-d H:i:s'); + + $post->save(); + + + $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'); + + $post = ORM::factory('post', $id); + $post->delete(); + + $redirect = URL::site($this->_redirect); + $this->request->redirect($redirect); } } diff --git a/application/classes/model/post.php b/application/classes/model/post.php new file mode 100644 index 0000000..2996f5c --- /dev/null +++ b/application/classes/model/post.php @@ -0,0 +1,14 @@ + array + ( + 'type' => 'mysql', + 'connection' => array( + 'hostname' => 'localhost', + 'username' => 'root', + 'password' => 'adminadmin', + 'persistent' => FALSE, + 'database' => 'bd_blog', + ), + 'table_prefix' => '', + 'charset' => 'utf8', + 'profiling' => TRUE, + ), +); diff --git a/application/views/site/postagens/page.php b/application/views/site/postagens/page.php index 078873e..7c5a8a5 100644 --- a/application/views/site/postagens/page.php +++ b/application/views/site/postagens/page.php @@ -6,46 +6,30 @@

=============================== Listar ================================

- + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + +
titulo cadastro ações
titulo cadastro ações
78Lorem ipsum dolor sit amet...23/07/2012 - novo - - editar - - excluir -
78Lorem ipsum dolor sit amet...23/07/2012 - novo - - editar - - excluir -
78Lorem ipsum dolor sit amet...23/07/2012 - novo - - editar - - excluir -
id; ?>titulo; ?>data_registro); + $data_registro = $data_registro->format('d/m/Y'); + + echo $data_registro; ?> + novo - + editar - + deletar +
-
« 1 2 3 4 »
+ + diff --git a/bd_blog.sql b/bd_blog.sql index 5c3d19e..0721ac0 100644 --- a/bd_blog.sql +++ b/bd_blog.sql @@ -1,11 +1,13 @@ +-- nome para banco de dados: bd_blog +-- configurar o arquivo em 'appication/config/database.php' , adcionar usuário e senha do banco -- POSTS CREATE TABLE IF NOT EXISTS `posts`( `id` INT(8) NOT NULL AUTO_INCREMENT, -`nome` VARCHAR(30) NOT NULL, +`titulo` VARCHAR(30) NOT NULL, +`chamada` TEXT NOT NULL, `texto` TEXT NOT NULL, -`user_admin` VARCHAR(50), `data_registro` DATETIME, PRIMARY KEY(`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/media/css/style.css b/media/css/style.css index 9d5c5b8..fed035c 100644 --- a/media/css/style.css +++ b/media/css/style.css @@ -121,10 +121,21 @@ select:focus { outline: none; } #postagens p{ margin: 10px 0px; } #postagens table{ width:500px; } -#postagens table tr{ height:20px; } -#postagens table tr td{ text-align: center; } +#postagens table th{ border-bottom: 1px solid #ccc; } +#postagens table th.titulo{ width:220px; padding: 0px 4px; text-align: left; } -#postagens .paginacao { font-size: 22px; text-align: center; margin: 20px; } +#postagens table tr{ height:30px; } +#postagens table tr td{ text-align: center; border-bottom: 1px solid #ccc; } +#postagens table tr td.titulo{ width:220px; padding: 0px 4px; text-align: left; } + +#postagens table tr td a{ color: #333; } +#postagens table tr td a.novo{ color: green; } +#postagens table tr td a.editar{ color: blue; } +#postagens table tr td a.deletar{ color: red; } + +#postagens .pagination .go_to{ font-size: 28px; color: #333; } +#postagens .pagination { font-size: 22px; text-align: center; color: #aaa; word-spacing: 10px; margin: 20px; } +#postagens .pagination a{ color: #333; } #postagens input[type="text"]{ font-size: 15px; padding: 4px 2px; } #postagens textarea{ font-size: 15px; padding: 4px 2px; } diff --git a/modules/pagination b/modules/pagination new file mode 160000 index 0000000..d1c34df --- /dev/null +++ b/modules/pagination @@ -0,0 +1 @@ +Subproject commit d1c34df4d64e63591793b73179ff21953071fd06