in Education by
I'm using the cacheCounter in CakePHP, which increments a counter for related fields. Example, I have a Person table a Source table. Person.source_id maps to a row in the Source table. Each person has one Source, and each Source has none or many Person rows. cacheCounter is working great when I change the value of a source on a person. It increments Source.Person_Count. Cool. But when it increments, it adds it to the destination source for a person, but doesn't remove it from the old value. I tried updateCacheControl() in afterSave, but that didn't do anything. So then I wrote some code in my model for afterSave that would subtract the source source_id, but it always did this even when I wasn't even changing the source_id. (So the count went negative). My question: Is there a way to tell if a field was changed in the model in CakePHP? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
To monitor changes in a field, you can use this logic in your model with no changes elsewhere required: function beforeSave() { $this->recursive = -1; $this->old = $this->find(array($this->primaryKey => $this->id)); if ($this->old){ $changed_fields = array(); foreach ($this->data[$this->alias] as $key =>$value) { if ($this->old[$this->alias][$key] != $value) { $changed_fields[] = $key; } } } // $changed_fields is an array of fields that changed return true; }

Related questions

0 votes
    I'm using the cacheCounter in CakePHP, which increments a counter for related fields. Example, I have a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I want to update order status to complete using webapi here is my testing code : $data = array ( ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    Wordpress site. I want jquery or php, or any easy solution that will grab div from div id=content ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    So this is a zany thing that I'm attempting to do, but what I am trying to achieve is querying ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    So this is a zany thing that I'm attempting to do, but what I am trying to achieve is querying ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    I am trying to make a API call to wikipedia through: http://en.wikipedia.org/w/api.php?action= ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 21, 2022 in Education by JackTerrance
0 votes
    In Laravel, there is a function return back();, which returns the user to the previous page. Is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    I have a script which loops over tables and fields doing a find and replace. The script takes around ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    I am struggling to figure out how to specify a MOTO payment with Stripe API and PHP. I believe I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I have a table structure like this : subscribers with attributes: id, status I want to have a way ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    I think I have an error in my code here - $('#form input[type=radio]').val();. JS: $( ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    I think I have an error in my code here - $('#form input[type=radio]').val();. JS: $( ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    I think I have an error in my code here - $('#form input[type=radio]').val();. JS: $( ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    I think I have an error in my code here - $('#form input[type=radio]').val();. JS: $( ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    How can I change the strpos to make it non case sensitive. The reason is if the product->name is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 24, 2022 in Education by JackTerrance
...