I don't know why this doesn't work (I am using CakePHP 2.1 and also tried 2.0):
Here is Model
class User extends AppModel
{
public $validate = array('username' => array('rule' => 'email'));
}
Here is Controller
class UsersController extends AppController
{
function index()
{
$this->set('users', $this->User->find('all') );
}
function add()
{
if (!empty($this->request->data))
{
if ($this->User->save($this->request->data))
{
$this->Session->setFlash('User has been registered.');
$this->redirect(array('action' => 'index'));
}
}
}
}
Here is add View
<h1>Add Post</h1>
<?php
echo $this->Form->create('User');
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->end('Register');
?>
And it validates whatever I write... And it should check if username is email...
It's impossible! It has to work! - but it doesn't...
I also checked it with cake php 2.0 and it still does't work - please help, it is so simple i has to work...
Maybe something with my db table is wrong???
CREATE TABLE `users` (
`id` int(10) unsigned not null auto_increment,
`username` varchar(50),
`password` varchar(50),
`created` datetime,
`modified` datetime,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=9;
This is very strange - in my app folder I only add 'UserModel.php', 'UserController.php' and 'add.ctp', and a db config - all that I wrote above - and validation doesn't work!!!