On cakephp 2.1, I’ve used this structure to intercept data upon saving:
$this->request->data['Setup']['active'] = 1;
Now, after editing a record (Dir), i want to redirect to it’s parent (project_id) by getting the parent id this way:
$ownParentId = $this->request->data['Dir']['project_id'];
But it’s just not getting any value to be passed here:
$this->redirect(array('controller' => 'projects', 'action' => 'edit', $ownParentId));
So my redirection fails.
============= After replies ==============
It seems the project_id is not traveling at all due to the following:
On my dir edit form I commented:
//echo $this->Form->input('project_id');
because user shouldn’t change the project id.
I just tried uncommenting that line and the form shows now an empty or null select control that posts nothing.
I was expecting an edit control i could somehow hide or disable.
field project_id on my dirs table
CREATE TABLE IF NOT EXISTS `dirs` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`project_id` int(10) NOT NULL,
....
tied to
id field on my projects table:
CREATE TABLE IF NOT EXISTS `projects` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`name` varchar(200) NOT NULL,
`pr_number` varchar(10) NOT NULL,
`client_id` int(5) NOT NULL,
`exec_id` int(5) NOT NULL,
....
project model
var $hasMany = array('Daily', 'Dir');
dir model
var $belongsTo = array('Project');
Perhaps i just need a nice find() structure to populate the project_id control on my edit form? -or-
to get the project_id value before saving the edit? (projectt_id is already saved since is an edit.
I’ve posted full dirs controller at http://carlosgarcia.us/support/DirsController.txt.
Can you help? Thank you very much.
Carlos
To redirect after editing or deleting a child record, first I got the parent id (edit/delete method on my controller)
and then redirect after saving:
To redirect to the parent record after adding a child was a bit more tricky -for me being a dummy-
1.- From my view, had the Add link sent a param I called parentProject:
2.- In my child controller, set this param to an array (add method):
3.- Before saving, set the field value for my child record:
4.- And used that same value to redirect after saving:
Additionally, this way allowed me to get all data I needed form parent model to be available when adding/editing child:
Just glad it worked and wanted to share for struggling starters like myself.
Carlos.