Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
602 views
in Technique[技术] by (71.8m points)

save() returning false, but with no error in CakePHP

My debug value is set to 2, and it's displaying all the queries, except the one I need.

I have an Items controller method that is calling this method in the User model (Item belongsTo User):

function add_basic($email, $password) {
    $this->create();

    $this->set(array(
        'email' => $email,
        'password' => $password
    ));

    if($this->save()) {
        return $this->id;
    }
    else {
        return false;
    }
}

I have confirmed that $email and $password are being passed into the function correctly (and are populated with legit data). email and password are the names of the fields in the User model.

I have also confirmed that on $this->save() it is returning false, but when I view the page where this occurs, the query is not being printed in the debug, and there is no error being thrown, so I have no idea whats going wrong.

Any ideas on how I can see the error, or why the query doesn't seem to be getting executed?

It's weird, cause right after this, I have another model saving data to it in the exact same fashion, it goes off without a hitch.

question from:https://stackoverflow.com/questions/2314632/save-returning-false-but-with-no-error-in-cakephp

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This will probably give you the info you need (assuming it's not saving because of invalid data, of course):

if(!$this->save()){
    debug($this->validationErrors); die();
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...