abhimir
(Abhimir)
August 11, 2011, 7:28am
1
I am trying to pass a variable from a view (of mobile model) to a different controller (of inventory model), using the chtml:button with this code
echo CHtml::button('Sell It', array('submit' => array('inventory/create', array('id'=>$data->id))));
Now how do I access the $id variable in the Inventory controller, so that I can prepopulate the create view with details corresponding to the passed ‘id’ variable of the mobile model.
Thanks
tuga
(Tuga74)
August 11, 2011, 8:39am
2
abhimir:
I am trying to pass a variable from a view (of mobile model) to a different controller (of inventory model), using the chtml:button with this code
echo CHtml::button('Sell It', array('submit' => array('inventory/create', array('id'=>$data->id))));
Now how do I access the $id variable in the Inventory controller, so that I can prepopulate the create view with details corresponding to the passed ‘id’ variable of the mobile model.
Thanks
You can get it on $_GET[‘id’]
abhimir
(Abhimir)
August 11, 2011, 9:01am
3
thanks. realised it after posting, and it is working now.
coy_coy
(Rexliterato)
October 18, 2012, 9:49am
4
may I know how to pass values from view to different controller?
I am using $this->createUrl() to access create action from different controller.
I tried including it into createUrl array, however it displayed to address bar.
view
<a href="<?php echo $this->createUrl('//po/local/requestDetails/create',array('request_number'=>$parentModel->request_number,'request_type'=>$parentModel->request_type,'priority'=>$parentModel->priority)); ?>">
controller
$childModel=new RequestDetails;
$childModel->request_number = $_GET['request_number'];
$priority = $_GET['priority'];
$request_type = $_GET['request_type'];
is there any other way to do it? I tried using activeHiddenField, however I am encountering an error "undefined index"
view
echo CHtml::activeHiddenField($parentModel,'request_type',array('value'=>$_GET['request_type']));
echo CHtml::activeHiddenField($parentModel,'priority',array('value'=>$_GET['priority']));
Thanks. I’m still new to this framework.
redguy
(Maciej Lizewski)
October 18, 2012, 10:04am
5
activeHiddenField will render hiddent fields with names like "ParentModel[priority]" instead of just "priority" so you should access them like this:
$priority = $_GET['ParentModel']['priority'];
where "ParentModel" is the example class name of $parentModel object.
also activeHiddenField requires the model class to have all needed attributes (like "priority", "request_type", etc). Just post more information on where you get this error - in view or in action referenced from view?
coy_coy
(Rexliterato)
October 18, 2012, 10:15am
6
redguy:
activeHiddenField will render hiddent fields with names like "ParentModel[priority]" instead of just "priority" so you should access them like this:
$priority = $_GET['ParentModel']['priority'];
where "ParentModel" is the example class name of $parentModel object.
also activeHiddenField requires the model class to have all needed attributes (like "priority", "request_type", etc). Just post more information on where you get this error - in view or in action referenced from view?
the error occurs when I access the form itself where activeHiddenField is located.
does activeHiddenField passes values from view to different controller instead of passing it through createUrl?