0

I have following piece of code:

public function check()
        {
            $result = $this->User->field('id', array('username' => 'alek@lol.pl'));
            debug($result);
        }

In my users table I have record:

NSERT INTO `users` (`id`, `username`, `password`, `role`, `created`, `modified`) VALUES 
('5', 'alek@lol.pl', '64c918dd65b67b455248c2498bcc5421a66b68a6', 'member', '2012-04-24 10:56:37', '2012-04-24 10:56:37');

and the result of this controller method check is:

false

And the sql query is:

Nr  Query   Error   Affected    Num. rows   Took (ms)
1   SELECT `User`.`id` FROM `freebooks`.`users` AS `User` WHERE `username` = 'alek@lol.pl' LIMIT 1      1   1   0

So SQL return one row but in cake result is 'false' - whats wrong? something broken??

when I execute this SQL statement in my PhpMyAdmin it correctly returns id = 5

And when I change one line to

$result = $this->User->find('all');

this prints

true

This is impossible!!!

4

1 回答 1

1
$this->User->field('id', array('username', $this->request->data['User']['username']));

你可以这样检查:

if(!empty($this->User->field('id', array('username', $this->request->data['User']['username']));)) {

  // code
}

或者

$id = $this->User->field('id', array('username', $this->request->data['User']['username']));

$this->User->id = $id;

if($this->User->exists()) {
  // code
}
于 2012-04-24T10:54:07.073 回答