cakephp无法使用集合更新表

cakephp无法使用集合更新表,php,mysql,cakephp,set,save,Php,Mysql,Cakephp,Set,Save,我在cakephp中更新数据库表时遇到问题。。。 因此,我有一个个人资料页面,登录的用户可以查看和更新他的个人信息。这是我的解决方案是的,我知道这不是最好的 if($this->request->is('post')) { $data = $this->request->data['user-profile']; // $uid = $this->Session->read("WebUser.id"); $uid = 1; $u

我在cakephp中更新数据库表时遇到问题。。。 因此,我有一个个人资料页面,登录的用户可以查看和更新他的个人信息。这是我的解决方案是的,我知道这不是最好的

if($this->request->is('post')) {
    $data = $this->request->data['user-profile'];
    // $uid = $this->Session->read("WebUser.id");
    $uid = 1;
    $user_data = $this->WebUser->find('first', array('conditions'=>array('id'=>$uid)));             
    $updated_fields = '';
    foreach($data as $key => $value) {
        if($key != 'state'){
            if(empty($value)) {                                                             
                $this->Session->setFlash("Please fill in all the required fields");
                return;
            }
        }               
        if($user_data['WebUser'][$key] != $value) {
            if($key == 'email') {
                $mail_check = $this->WebUser->find('first', array('conditions'=>array('email'=>$value, 'id !='=>$uid)));
                if($mail_check) {
                    $this->Session->setFlash("This e-mail is already registered");
                    return;
                }
            }
            $updated_fields .= "'".$key."'=>'".$value."',";
        }               
    }
    if($updated_fields != '') {
        $updated_fields .= "'modified'=>'".date("Y-m-d H:i:s")."'";
        $this->WebUser->read(null, $uid);
        $this->WebUser->set(array('first_name'=>'John','modified'=>'2014-12-30 10:53:00'));
        if($this->WebUser->save()) {
            $this->printr($this->data);
            $this->WebUser->save();
            $this->Session->setFlash("Success : Profile data is now modified", array("class"=>"success_msg"));
        } else {
            $this->Session->setFlash("Error : Data modifying isn't complete. Please try again!");
        }
    }
    return;
 }
因此,这段代码从数据库中获取用户信息,并查找在配置文件页面上编辑的字段。问题是,当我想保存数据时,它会返回false,但没有保存它。。。有人对此有解决办法吗?

试着把 $this->WebUser->validationErrors; 在else部分中,检查是否存在任何验证错误

像这样:

if($this->WebUser->save()) {
                $this->printr($this->data);
                $this->WebUser->save();
                $this->Session->setFlash("Success : Profile data is now modified", array("class"=>"success_msg"));
            } else {
                echo "<pre>";print_r($this->WebUser->validationErrors);die();
                $this->Session->setFlash("Error : Data modifying isn't complete. Please try agin!");
            }
你试过设置身份证吗

此外,CakePHP在任何事务之后都会自动更新表中的字段。因此,您不必直接设置它,但如果需要任何其他日期值,您可以设置它

关于验证。我建议您阅读CakePHP中的内容,因为验证并不好,它可以由模型处理

还有。您可以使用Model:$validationErrors从模型中获取任何验证错误


这段代码的问题是不想保存发布的数据调试$this->WebUser->save已经返回false。最后,我没有找到这段代码不起作用的解决方案,但结论是,您永远不需要使用多个用户表。现在我有了一个Users和Groups表,不同类型的用户连接到他们的groupsAdmin,User

用户提交此表单时是否打印错误消息?另外,请附上您的查看代码。我想是edit.ctp之类的。。。
$this->WebUser->id = $uid;
debug($this->Recipe->validationErrors);