Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6806431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:42:35+00:00 2026-05-26T19:42:35+00:00

I’m trying to load , edit and save a record with CakePHP 2.0 but

  • 0

I’m trying to load, edit and save a record with CakePHP 2.0 but I get a generic error during the save method that don’t help me to understand where is the problem.

if I try with debug($this->User->invalidFields()); I get an empty array, but I get false from $this->User->save() condition.

Here is the controller action where I get the error:

public function activate ($code = false) {
    if (!empty ($code)) {

        // if I printr $user I get the right user
        $user = $this->User->find('first', array('activation_key' => $code));

        if (!empty($user)) {
            $this->User->set(array (
                'activation_key' => null,
                'active' => 1
            ));

            if ($this->User->save()) {
                $this->render('activation_successful');
            } else {
                // I get this error
                $this->set('status', 'Save error message');
                $this->set('user_data', $user);
                $this->render('activation_fail');
            }
            debug($this->User->invalidFields());

        } else {
            $this->set('status', 'Account not found for this key');
            $this->render('activation_fail');
        }
    } else {
        $this->set('status', 'Empty key');
        $this->render('activation_fail');
    }
}

When I try the action test.com/users/activate/hashedkey I get the activation_fail template page with Save error message message.

If I printr the $user var I get the right user from cake’s find method.

Where I’m wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:42:36+00:00Added an answer on May 26, 2026 at 7:42 pm

    I think the problem may be in the way you’re querying for the User record. When you do this:

    $user = $this->User->find('first', array('activation_key' => $code));
    

    The variable $user is populated with the User record as an array. You check to ensure it’s not empty, then proceed; but the problem is that $this->User hasn’t been populated. I think if you tried debug($this->User->id) it would be empty. The read() method works the way you’re thinking.

    You could try using the ID from that $user array to set the Model ID first, like so:

    if (!empty($user)) {
        $this->User->id = $user['User']['id']; // ensure the Model has the ID to use
        $this->User->set(array (
            'activation_key' => null,
            'active' => 1
        ));
        if ($this->User->save()) {
        ...
    

    Edit: Well another possible approach is to use the $user array instead of modifying the current model. You said that you get back a valid user if you debug($user), so if that’s true you can do something like this:

    if (!empty($user)) {
        $user['User']['activation_key'] = null;
        $user['User']['active'] = 1;
        if ($this->User->save($user)) {
        ...
    

    This method works in the same way as receiving form data from $this->request->data, and is described on the Saving Your Data part of the book.

    I’m curious though if there’s another part of your setup that’s getting in the way. Can other parts of your app write to the database properly? You should also check to make sure you aren’t having validation errors, like their example:

    <?php
    if ($this->Recipe->save($this->request->data)) {
        // handle the success.
    }
    debug($this->Recipe->validationErrors);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.