[英]set current model to database object in cakephp
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));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.