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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:35:59+00:00 2026-06-05T13:35:59+00:00

On cakephp 2.1, I’ve used this structure to intercept data upon saving: $this->request->data[‘Setup’][‘active’] =

  • 0

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

  • 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-06-05T13:36:02+00:00Added an answer on June 5, 2026 at 1:36 pm

    To redirect after editing or deleting a child record, first I got the parent id (edit/delete method on my controller)

         $ownParentId = $this->Dir->find
                        (
                        'first', array
                    (
                    // recursive 0 so no child tables travel, use 1 to retrieve ALL tables  
                    'recursive' => 0,
                    'fields' => array('Dir.project_id'),
                    'conditions' => array('Dir.id' => $id)
                        )
        );
    

    and then redirect after saving:

    $this->redirect(array('controller' => 'projects', 'action' => 'edit', $ownParentId['Dir']['project_id']));
    

    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:

    echo $this->Html->link(__('Add'), array('controller' => 'dirs', 'action' => 'add', 'parentProject' => $project['Project']['id']));  
    

    2.- In my child controller, set this param to an array (add method):

    $this->set('parentProject', $this->request->params['named']['parentProject']);
    

    3.- Before saving, set the field value for my child record:

    $this->request->data['Dir']['project_id'] = $this->request->params['named']['parentProject'];  
    

    4.- And used that same value to redirect after saving:

    $this->redirect(array('controller' => 'projects', 'action' => 'edit', $this->request->data['Dir']['project_id']));  
    

    Additionally, this way allowed me to get all data I needed form parent model to be available when adding/editing child:

       $ProjectData = $this->Dir->Project->find
                        (
                        'first', array
                    (
                    // recursive 0 so no child tables travel, use 1 to retrieve ALL tables  
                    'recursive' => 0,
                    'fields' => array('Project.name', 'Project.pr_e_start'),
                    'conditions' => array('Project.id' => $this->request->params['named']['parentProject'])
                        )
        );
    
        $this->set(compact('ProjectData'));
    

    Just glad it worked and wanted to share for struggling starters like myself.

    Carlos.

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

Sidebar

Related Questions

In cakephp, I used $rNo array in WHERE clause. $rooms =$this->find('all',array( 'conditions'=>array(NOT=>array('Room.id'=>$rNo)), 'group'=>array('Room.room_type_id'))); Now,
the cakephp rest tutorial says that post data should be in $this->data, but I
CAKEPHP Group by problem in paginate.. This is my table structure Friends Table `id`
my CakePHP (1.2.5.) doesn't validate my form correct. $this->UserData->save($this->data); gives me always a true
Using CakePHP 1.3 , I post a form which correctly fills in $this->data .
CakePHP cannot get multiple emails send after a previous execution.. this is an example:
CakePHP has a requireSecure function in the SecurityComponent. I'm using this to force SSL
CakePHP Newbie :) I am having trouble accessing another controller and passing that data
In CakePHP 2.0 version, I have written something like this in UsersController.php public function
The CakePHP framework is a layered structure. My question is: Where (theoretically) is the

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.