How do you set the model to a database object in an efficient way? What is the better way to do this than below?
$user = $this->User->findByPassword($password, array('fields'=>'id'));
$this->User = new User($user["User"]["id"]);
$this->User->read();
print_r($this->User);
I've looked everywhere but i can't find it.
you mean:
$user = $this->User->findByPassword($password, array('fields'=>'id'));
$this->User->id = $user["User"]["id"]; //set the id
print_r($this->User);
I got it by accident. This is the one-liner i was looking for.
$this->User->set($this->User->findByPassword('first',$password));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.