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 854469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:55:39+00:00 2026-05-15T07:55:39+00:00

I got a few lines of codes in a Model in cakePHP 1.26: function

  • 0

I got a few lines of codes in a Model in cakePHP 1.26:

function beforeSave() { 
        $this->data['User']['pswd'] = md5($raw['User']['pswd']);              
         return true;
                         } // this beforeSave() works

The code above has been tested and it is working in my database.
Yet, I am not sure if I can understand it well,
so, I re-wrote the code in other way, and it just failed to work then.

 function beforeSave() { 
            $raw=$this->data;       
            $raw['User']['pswd'] = md5($raw['User']['pswd']);                    
             return true;
                             } // this beforeSave() failed to work

Why the second method can not work?

  • 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-15T07:55:40+00:00Added an answer on May 15, 2026 at 7:55 am

    In this line:

    $raw=$this->data
    

    You’re just assigning $this->data by value to $raw. So when you change $raw‘s array data, $this->data isn’t affected by the change.

    Besides, you’re totally changing the meaning of your code. What you end up doing is replacing $raw‘s data with $this->data from your model. I’ve not worked with CakePHP before, but I assume $raw already contains all the raw data you’ve received through some kind input, while $this->data in your model contains the older version of your model data (for example, an older password that the user was going to change). Your changed code will just erase all the new data in $raw, which I don’t think is what you intend to do judging from your first code example.

    To give you a little explanation of this line:

    $this->data['User']['pswd'] = md5($raw['User']['pswd']);
    

    It’s pretty simple: the pswd item in the User array of $this->data is set as the MD5 checksum of the pswd in the User array of $raw.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have googled whole day, got few answers how to do this, and
I got a few question about this IDE. First, when boot up vs2010, it
I've got a few queries (20+) which all return the following three columns: Building
I've got a few lines of code for iterating over a dict within a
Ok, so here's what I've got: Few lines of code, which get chosen/taken photo
i have form in drupal which uploads images and has got few checkboxes in
I got a few WCFs that are running on an intranet on IIS 7.
I have got a few tables which I am trying to join. I just
I've got a few controllers here at work that contain methods I can use
I've got a few loading bars that appear during any postbacks. How can I

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.