Criando um post e um controller
Para, por exemplo:
Configure::write('Security.salt', 'teste');
Também a linha 192:
Configure::write('Security.cipherSeed', '76859309657453542496749683645');
Para, por exemplo:
Configure::write('Security.cipherSeed', '123456');
Agora, acesse o site e tecle F5: http://localhost/blog
Os notices devem desaparecer.
Caso esteja usando
GNU/Linux, talvez precise ajustar permissões no
app/tmp.
Na dúvida, veja:
Ativando o módulo mod_rewrite
Se tiver dúvida, veja:
Criando um Post do Model
Crie o arquivo:
app/Model/Post.php
Contendo:
<?php
class Post extends AppModel {
}
Cake deve dinamicamente criar um objeto model para você, caso ele não encontre um arquivo correspondente em
app/Model.
Criar um Post do Controller
O controller é onde toda a lógica de negócios, para a interação com o Post, deve aparecer.
Criar o arquivo:
app/Controller/PostsController.php
Inicialmente contendo:
<?php
class PostsController extends AppController {
public $helpers = array('Html', 'Form');
}
Vamos adicionar uma 'ação/action' para o controller:
<?php
class PostsController extends AppController {
public $helpers = array('Html', 'Form');
public function index() {
$this->set('posts', $this->Post->find('all'));
}
}
Mais sobre Controllers:
Criando um post do Viewer
Esta é a camada de apresentação que pode conter HTML misturado com PHP, ou XML, CVS e até dados binários.
Crie o arquivo:
app/View/Posts/index.ctp
Contendo:
<h1>Blog posts</h1>
<table>
<tr>
<th>Id</th>
<th>Title</th>
<th>Created</th>
</tr>
<!-- Here is where we loop through our $posts array, printing out post info -->
<?php foreach ($posts as $post): ?>
<tr>
<td><?php echo $post['Post']['id']; ?></td>
<td>
<?php echo $this->Html->link($post['Post']['title'],
array('controller' => 'posts', 'action' => 'view', $post['Post']['id'])); ?>
</td>
<td><?php echo $post['Post']['created']; ?></td>
</tr>
<?php endforeach; ?>
</table>
Detalhes em:
Edite o
PostsController.php, e deixe assim:
<?php
class PostsController extends AppController {
public $helpers = array('Html', 'Form');
public function index() {
$this->set('posts', $this->Post->find('all'));
}
public function view($id = null) {
$this->Post->id = $id;
$this->set('post', $this->Post->read());
}
}