I am working on a feature to edit all the items in the table.
Here is my edit action from my controller:
public function editAll()
{
$this->set('isEditAllValid', false);
$this->set('editAllValidationErrors', false);
if ($this->request->is('post'))
{
$this->LocalClock->table = 'local_clocks';
$this->LocalClock->getDataSource()->tableFields['local_clocks'] = array( "id", "name", "auto_offset", "utc_offset_sec", "in_month", "in_week", "in_day", "in_hour", "out_month", "out_week", "out_day", "out_hour", "offset_sec");
$this->set('localClocksEntries', $this->LocalClock->find('all'));
if ($this->LocalClock->save($this->request->data))
{
foreach($localClocksEntries as $LocalClock)
{
$this->set('LocalClock', $this->request->data);
$this->LocalClock->save($LocalClock);
$this->set('isEditAllValid', true);
$this->set('editAllValidationErrors', false);
}
}
else
{
$this->set('isEditAllValid', false);
$this->set('editAllValidationErrors', true);
}
}
}
What I am doing in the code is, set some boolean variables to false (validation stuff), then if the action is a post grab the local clocks table and insert that into a variable for storage. Then loop through that variable and save the data that was posted to each item in the table.
I don’t know why but I am getting2 errors when trying to edit all.
Notice (8): Undefined variable: localClocksEntries [APP/Controller/LocalClocksController.php, line 158]
Warning (2): Invalid argument supplied for foreach() [APP/Controller/LocalClocksController.php, line 158]
Basically I just want to loop through every row in the table and change the contents to what the user entered in the form.
This sets a variable for the view. It does not create that variable in the current scope. So the variable
$localClocksEntriesdoes not exist inforeach ($localClocksEntries .... If you want to use the variable in the current scope and pass it on to the view, do: