Commits

Evaldo Junior  committed 9974941

Criando a interface de administração

Criei a lista de posts e o formulário para cadastrar um novo post.
Este formulário ainda não valida nem grava.

  • Participants
  • Parent commits 67d36e0

Comments (0)

Files changed (5)

File application/controllers/admin/posts.php

+<?php
+
+class Posts extends CI_Controller
+{
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * index 
+     *
+     * Lista os posts para edição e exibe um botão para novos posts
+     * 
+     * @access public
+     * @return void
+     */
+    public function index()
+    {
+        $this->load->model('posts_model');
+        $this->load->helper('datas');
+
+        $data = array();
+
+        $data['view'] = 'admin/posts/index';
+        $data['posts'] = $this->posts_model->pegar_todos();
+
+        $this->load->view('admin/base', $data);
+    }
+
+    /**
+     * novo 
+     *
+     * Cadastrar um novo post
+     * 
+     * @access public
+     * @return void
+     */
+    public function novo()
+    {
+        $this->load->model('posts_model');
+        $this->load->helper('form');
+
+        $data = array();
+
+        $data['view'] = 'admin/posts/novo';
+
+        $this->load->view('admin/base', $data);       
+    }
+}

File application/views/admin/base.php

+<!DOCTYPE html>
+<html>
+    <head>
+        <meta charset="utf-8">
+        <title>ADMIN - Blog CI</title>
+
+        <link
+            rel="stylesheet"
+            href="<?php echo base_url('assets/css/base.css'); ?>"
+            type="text/css"
+        >
+        <link
+            rel="stylesheet"
+            href="<?php echo base_url('assets/css/admin.css'); ?>"
+            type="text/css"
+        >
+
+    </head>
+    <body>
+
+        <div id="corpo_admin">
+
+            <h1>ADMIN - Blog CI</h1>
+            <hr />
+
+            <?php if ($this->session->flashdata('mensagem')) : ?>
+                <div id="mensagem">
+                    <p><?php echo $this->session->flashdata('mensagem'); ?></p>
+                </div>
+            <?php endif; ?>
+
+            <!-- Carregamento das views -->
+            <?php $this->load->view($view); ?>
+        </div><!-- corpo_admin -->
+
+        <footer>
+            <hr />
+            <p>
+                &copy; 2012 - Turbine-se com CodeIgniter
+            </p>
+            <p>
+                Blog desenvolvido no curso Trubine-se com CodeIgniter
+            </p>
+        </footer>
+    </body>
+</html>

File application/views/admin/posts/index.php

+<div>
+    <a href="<?php echo site_url('admin/posts/novo'); ?>" class="botao">Novo post</a>
+</div>
+
+<?php foreach ($posts as $p) : ?>
+    <div class="lista">
+        <h2>
+            <a href="<?php echo site_url('posts/post/'.$p->url); ?>">
+                <?php echo $p->titulo; ?>
+            </a>
+        </h2>
+        <p>
+            <em>
+                Publicado por: <?php echo $p->autor; ?> em
+                <?php echo formatar_data_exibicao($p->publicacao); ?>
+            </em>
+        </p>
+    </div>
+<?php endforeach; ?>

File application/views/admin/posts/novo.php

+<?php echo anchor('admin/posts', 'Cancelar'); ?>
+
+<h2>Novo post</h2>
+
+<?php
+    echo form_open();
+
+        echo form_error('form_post_titulo');
+        echo form_label('Título :', 'form_post_titulo');
+        echo form_input(array(
+            'name'      => 'form_post_titulo',
+            'id'        => 'form_post_titulo',
+            'value'     => set_value('form_post_titulo', ''),
+            'maxlength' => 60
+        ));
+
+        echo form_error('form_post_autor');
+        echo form_label('Autor :', 'form_post_autor');
+        echo form_input(array(
+            'name'      => 'form_post_autor',
+            'id'        => 'form_post_autor',
+            'value'     => set_value('form_post_autor', ''),
+            'maxlength' => 20
+        ));
+
+        echo form_error('form_post_texto');
+        echo form_label('Texto :', 'form_post_texto');
+        echo form_textarea(array(
+            'name'      => 'form_post_texto',
+            'id'        => 'form_post_texto',
+            'value'     => set_value('form_post_texto', ''),
+            'rows'      => 9
+        ));
+
+        echo form_error('form_post_tags');
+        echo form_label('Tags :', 'form_post_tags');
+        echo form_input(array(
+            'name'      => 'form_post_tags',
+            'id'        => 'form_post_tags',
+            'value'     => set_value('form_post_tags', ''),
+            'maxlength' => 100
+        ));
+
+        echo form_submit('', 'Enviar', 'class="botao"');
+
+    echo form_close();
+?>

File assets/css/admin.css

+body {
+    background-color: #411;
+}
+
+#corpo_admin {
+    background-color: #fff;
+    margin: 0 auto;
+    width: 80%;
+    padding: 10px;
+}
+
+div.lista {
+    background-color: #ddd;
+    padding: 10px;
+    margin-top: 15px;
+}
+
+.botao {
+    background-color: #ccc;
+    font-size: 16px;
+    text-decoration: none;
+    border-radius: 5px;
+    display: inline-block;
+    padding: 5px;
+    color: #444;
+    font-weight: bold;
+    border: 1px solid #111;
+    cursor: pointer;
+}
+
+footer {
+    background-color: #fff;
+    text-align: center;
+}