This is my form:
echo $this->Form->create(null, array('url' => '/offices/addOffice'));
echo $this->Form->input('id', array('type' => 'hidden',
'value' => $this->data['Agency']['id']));
echo $this->Form->end(__('Add Office', true));
Now in the addOffice function I would like to get the value sent from this form.
What I did is:
function addOffice($id = null){
$this->set(compact('id'));
}
but it doesn’t send the $id to the view. What am I doing wrong?
I’m not sure what you’re asking, because if you want to “get the value sent from this form”, then “send the $id to the view” doesn’t have anything to do with it.
If you want to retrieve the the data from the form, you shouldn’t put
nullas the model’s name. Use the relevant model, which I assume is “Office” in this case.Now the id can be retrieved from
$this->data[ 'Office' ][ 'id' ]in the controller.If the question is how you can set the id in the first place using the function parameter, you have to use the
$idparameter you’ve set in the controller: