Passing variable from view to diff controller using Chtml::button

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.


You can get it on $_GET[‘id’]

thanks. realised it after posting, and it is working now.

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.


<a href="<?php echo $this->createUrl('//po/local/requestDetails/create',array('request_number'=>$parentModel->request_number,'request_type'=>$parentModel->request_type,'priority'=>$parentModel->priority)); ?>">


$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"


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.

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?