How to you extend a cakePHP project so it can use a new field in the database?
I just given a CakePHP Project that I am trying to extend the model to include a new field. I The original Developer is no longer available, and I haven't worked with CakePHP previously. The problem is that all of the other fields are being saved correctly, but the new field is being saved as an empty string.
The database has been extended to include the new field:
class_time varchar(30)
I extended the original view to support the new field
<?=$form->input('release', array('type' => 'radio', 'legend' => false, 'div' => 'radio', 'options' => array('Agree' => 'Agree ', 'Disagree' => 'Disagree')))?>
<?=$form->input('class_time', array('type' => 'radio', 'legend' => false, 'div' => 'radio', 'options' => array('No preference' => 'No preference ', '6:00-8:30 P.M. ' => '6:00-8:30 P.M. ', '6:30-9:00 P.M.' => '6:30-9:00 P.M.')))?>
As near as I can tell, the page is rendering the HTML correctly
<div class="radio"><input type="hidden" name="data[Account][release]" id="AccountRelease_" value=""><input type="radio" name="data[Account][release]" id="AccountReleaseAgree" value="Agree"><label for="AccountReleaseAgree">Agree </label><input type="radio" name="data[Account][release]" id="AccountReleaseDisagree" value="Disagree"><label for="AccountReleaseDisagree">Disagree</label></div>
<div class="radio"><input type="hidden" name="data[Account][class_time]" id="AccountClassTime_" value=""><input type="radio" name="data[Account][class_time]" id="AccountClassTimeNoPreference" value="No preference"><label for="AccountClassTimeNoPreference">No preference </label><input type="radio" name="data[Account][class_time]" id="AccountClassTime6:00-8:30P.m." value="6:00-8:30 P.M. "><label for="AccountClassTime6:00-8:30P.m.">6:00-8:30 P.M. </label><input type="radio" name="data[Account][class_time]" id="AccountClassTime6:30-9:00P.m." value="6:30-9:00 P.M."><label for="AccountClassTime6:30-9:00P.m.">6:30-9:00 P.M.</label></div>
But when it saves, it is saving the selection for the "release" field (and the others), but not the class_time.
From what I can find in the cakePHP documentation, app/models/account.php is where I believe I would need to define the new field, but it only consists of the following:
<?php
class Account extends AppModel {
var $name = 'Account';
}
?>
Which makes me wonder how the original developer got the "release" to save, even though it doesn't appear to be defined.
Is there something that I am missing, or that still needs to be done?
Whenever you make any changes to your database, please make sure that your app/config/core.php
file debug value is 2. Configure::write('debug', 2);
If it is 0 database changes will not be detected.
In CakePHP application, whenever you add a new field or modify the structure in database, you should delete all files inside YourApplication/app/tmp/cache/models folder.
Whenever you do any database change follow the following steps :
Quite a bit later, but I was looking for a way to do this today in Cake 3.x. Easiest way, imo:
bin/cake orm_cache build
which will rebuild the cache w/ the current db structure.
Or to just clear w/o rebuild:
bin/cake orm_cache clear
http://book.cakephp.org/3.0/en/console-and-shells/orm-cache.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With