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

  • Home
  • SEARCH
  • 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 923555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:12:44+00:00 2026-05-15T19:12:44+00:00

I have been trying to figure out how to do this and it seems

  • 0

I have been trying to figure out how to do this and it seems that its not something that many people are trying to do in cakephp or I am just completely misunderstanding the documentation.. I am using the following query below to get a field value so I get a value where the “findbycreated” is 0… this part works fine

$unregisteredemail = $this->Testmodel->findBycreated('0');
$emailaddress = $unregisteredemail['Testmodel']['emailaddress'] ;
$emailpassword = $unregisteredemail['Testmodel']['password'] ;

But now, after I do some things with this data that I retrieved, I want to mark a field, in the same row, in the same model / table as a value of ‘1’ to indicate that an action has taken place (email address has been successfully created, for example)… I just can’t figure out how to do this in cakephp despite my efforts of going through the documentation and searching, this should be rather simple, I am tempted, at this point, to just use a regular mysql query as its a simple query.. basically the query is (please excuse my syntax as I haven’t used direct mysql queries in a while) “update (database / table) set ‘created’=’1′ where ’emailaddress’=$emailaddress”

Or I could use the row ID, if needed, as cakephp seems to prefer this, but still can’t get how to do this.. this is my attempt below that is not working:

// update database to show that email address has been created
$this->Testmodel->read('emailaddress', $this->Testmodel->findBycreated('0'))
$this->Testmodel->id = 1;
$this->Testmodel->set(array(
            'created' => '1'
            ));

 $this->Testmodel->save();
  • 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-15T19:12:45+00:00Added an answer on May 15, 2026 at 7:12 pm

    There are, as you can see from the previous answers, several ways to achieve the same end. I’d just like to explain a little about why your way didn’t work.

    In the model, CakePHP has abstracted the database row(s) into an array according its implementation of ORM . This provides us with a handy way of manipulating the data and chucking it around the MVC architecture.

    When you say:

    $this->Testmodel->set(array(
                'created' => '1'
                ));
    

    You are dealing directly with the model, but the data is actually stored, as an array, in a class variable called $data. To access and manipulate this data, you should instead say:

    $this->data['Testmodel']['created'] => '1';
    

    The reason for specifying the model name as the first index is that where associated tables have been retrieved, these can be accessed in the same way, so you might have , for instance:

    Array([Testmodel] => Array ([id] => 1,
                                [created] => [1],
                                ...
                               )
          [Relatedmodel] => Array ([id] => 1,
                                   [data] => asd,
                                ...
                               )
         )
    

    …and so on. Very handy.

    Now, when you use $this->MyModelName->save() with no parameters, it uses $this->data by default and uses the part of the array of data appropriate to the model you are calling the save method on. You can also pass an array of data, formatted in the same way if, for some reason, you don’t (or can’t) use $this->data.

    Your use of the method read() is incorrect. The first parameter should be null, a string or an array of strings (representing fieldname(s)). The second parameter should be the id of the record you wish to read. Instead, for param 2, you are passing the result of a find, which will be an array. The result, which you are not capturing, will be empty.

    I would write your code like:

    $this->data = $this->Testmodel->read('emailaddress',1); 
    $this->data['Testmodel']['created'] = 1;
    $this->Testmodel->save();
    

    or more succinctly:

    $this->Testmodel->id = 1;
    $this->Testmodel->saveField('created', 1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to figure this out for some time. It seems lots
I have been trying to figure this out for quite a while, but what
I have been trying to figure this out for way to long tonight. I
So I have been trying to figure this out for a while, but nothing
I have been trying to figure out why I am getting this problem and
I have been scratching my head for hours trying to figure out why this
I have been pulling my hair trying to figure this out but nothing is
I've been pulling out my hair trying to figure this problem out. I have
I have been trying to figure this out for a bit. I create a
I have been trying to figure out how to read paragraph content which exists

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.