Mam takie pytanie co moze być nie tak że walidacja mi wogole nie działa w PHP Cake?
Robie sobie przykładową aplikację blog ze strony: http://book.cakephp.org/view/1528/Blog
Mam kontroler PostsController a w nim:
Kod
function edit($id = null) {
$this->Post->id = $id;
if(empty($this->data)) {
$this->data = $this->Post->read();
} else {
if ($this->Post->validates())
{
if($this->Post->save($this->data)) {
$this->Session->setFlash('Your post has been updated.');
$this->redirect(array('action' => 'index'));
}
}
else
{
$errors = $this->Post->invalidFields();
var_dump($errors);
exit;
}
}
$this->Post->id = $id;
if(empty($this->data)) {
$this->data = $this->Post->read();
} else {
if ($this->Post->validates())
{
if($this->Post->save($this->data)) {
$this->Session->setFlash('Your post has been updated.');
$this->redirect(array('action' => 'index'));
}
}
else
{
$errors = $this->Post->invalidFields();
var_dump($errors);
exit;
}
}
model jest taki:
Kod
<?php
class Post extends AppModel
{
var $name = 'Post';
var $validate = array(
'title' => array(
'required_title' => array(
'rule' => array('required'),
'message' => 'Błąd'
)
)
);
}
?>
class Post extends AppModel
{
var $name = 'Post';
var $validate = array(
'title' => array(
'required_title' => array(
'rule' => array('required'),
'message' => 'Błąd'
)
)
);
}
?>
Jak robie var_dump($this->Post) to zauważyłem ze tablica validate jest empty.
Podejrzewam ze cos innaczej powinno być w modelu ale jeszcze nei wiem co, z góry dzięki za pomoc. Informacyjnie jeszcze dodam ze używam cake 1.3.
--
Piotrek