如何在Cakephp中保存特定字段
这是我的密码如何在Cakephp中保存特定字段,cakephp,cakephp-2.0,cakephp-2.1,Cakephp,Cakephp 2.0,Cakephp 2.1,这是我的密码 public function settings(){ $this->loadModel('Userinfo'); $helpers = array('TimeZoneHelper'); if($this->request->is('post')) { $id = $this->Auth->User('idUser'); $data = $this->request->data['Userinfo'
public function settings(){
$this->loadModel('Userinfo');
$helpers = array('TimeZoneHelper');
if($this->request->is('post')) {
$id = $this->Auth->User('idUser');
$data = $this->request->data['Userinfo']['timezone'];
$this->Userinfo->save($data,array(
'conditions' => array('Userinfo.User_id' => $id))));
}
我在我的userinfo表中有一个字段名timezone。。我想更新一下。。我不知道如何特别更新Cakephp中的单个字段,因为我是Cakephp新手。我正在这样做,但不知道为什么它不起作用……当我调试$data时。。数据很好。。
在数据库中,时区的数据类型为“time”设置您的型号id:
$this->Userinfo->id=$id代码>
然后,使用savefield函数保存特定字段:
$this->Userinfo->saveField('timezone','UTC')代码>
祝你在cakePhp上好运 你在这里没有表现出太多的努力-这类问题有10个,如果不是100个的话,重复的问题也有10个-这也包括在和中。看起来你只是在编代码(传递条件来保存?你在哪里看到的?)。