CakePHP 2.0无法保存 [英] CakePHP 2.0 cannot save

查看:107
本文介绍了CakePHP 2.0无法保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用CakePHP 2.0,我有以下保存代码:

I'm using CakePHP 2.0, I have the following save code:

$to_save = array(
            'User' => array(
                'uid'=>$uid,
                'firstname'=>$firstname,
                'lastname'=>$lastname,
                'bio'=>$bio,
                'gender'=>$gender,
                'link'=>$link,
                'username'=>$username,
                'email'=>$email
            )
        );

$this->User->create();

if( $this->User->save( $to_save ) ){
    echo 'User was saved.';
}else{
    echo 'User not saved.';
}

但它总是输出用户未保存。感谢任何帮助! / p>

But it always output 'User not saved.' Thanks for any help!

推荐答案

如果没有查询错误,您可能在模型中有一些防止数据保存的验证规则。您可以添加 debug($ this-> User-> invalidFields())来查看是否以及哪些字段验证失败。

If there are no query errors, you probably have some validation rules in the model that prevent the data from saving. You can add debug( $this->User->invalidFields() ) to see if and which fields fail validation.

这篇关于CakePHP 2.0无法保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆