Temat: Walidacja z oficjalnej dokumentacji
Witam,
Robię tutorial z BLOG-iem (oficjalna dokumentacja): tutaj
Model, kontroler i widok wyglądają jak w w/w linku (dla pewności załączam poniżej), ale walidacja nie działa.
Czy to dlatego, że korzystam z CakePHP 1.3.0-beta, czy dlatego że wykorzystuję SQLite3?
posts.php
<?php
class Post extends AppModel
{
var $name = 'Post';
var $validate = array(
'title' => array(
'rule' => 'notEmpty'
),
'body' = array(
'rule' => 'notEmpty'
)
);
}
?>controllers/posts_controller.php
<?php
class PostsController extends AppController
{
var $name = 'Posts';
function index()
{
$this->set('posts', $this->Post->find('all'));
}
function view($id = null)
{
$this->Post->id = $id;
$this->set('post', $this->Post->read());
}
function add()
{
if (!empty($this->data))
{
if ($this->Post->save($this->data))
{
$this->Session->setFlash('Your post has been saved.');
$this->redirect(array('action' => 'index'));
}
}
}
}
?>views/posts/index.ctp
<?php echo $html->link('Add Post', array('controller' => 'posts', 'action' => 'add')); ?>
<table>
<tr>
<th>id</th>
<th>title</th>
<th>created</th>
</tr>
<?php foreach ($posts as $post): ?>
<tr>
<td><?php echo $post['Post']['id']; ?></td>
<td>
<?php echo $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>views/posts/add.ctp
<h1>Add Post</h1>
<?php
echo $form->create('Post');
echo $form->input('title');
echo $form->input('body', array('rows' => '3'));
echo $form->end('Save Post');
?>