Many sub form in a view

Hi everyone,

(I’m a newbie with yii and I’m french so excuse my english…)

I would like to make a view with a displaying of many subform

so i decided to call the CMenu widget

The main idea is that the user can select the sub form that he wants to see in this CMenu, when he selects a choice , the view loads itself by sending a variable to itself called ‘$valeur’


$this->widget('zii.widgets.CMenu',array(

			'items'=>array(

				array('label'=>'Key_user', 			'url'=>array("/functional_domain/view&id=".$model->FUNCTIONAL_DOMAIN_ID.""),'valeur'=>"key_user"),

				array('label'=>'Business_analyst', 	'url'=>array("/functional_domain/view&id=".$model->FUNCTIONAL_DOMAIN_ID.""),'valeur'=>"business_analyst"),

			),

		)); 

then, i wanted to make a simple condition to display the table the user selected whith a widget like that


if( $valeur=="business_analyst")

{	

	$this->widget('zii.widgets.grid.CGridView', array(

		'id'=>'child-grid',

		'dataProvider'=>$business_analystRecords,

		'columns'=>array(

			'BA_ID',	

			'BA_NAME',			

		),

	)); 

}

else if ($valeur=="key_user")

{

	$this->widget('zii.widgets.grid.CGridView', array(

		'id'=>'child-grid',

		'dataProvider'=>$key_userRecords,

		'columns'=>array(

				'KU_ID',

				'KY_NAME',	

		),

	));

}

but there is an evident problem, yii tells me he can’t find this $valeur variable, i don’t know where and how to create it, here is my controler with the associated methods

(if i send the variable


public function actionView($id)

	{

		$first_parent_instance=Sdm::model()->find();

		

		$this->render('view',array(

			'model'=>$this->loadModel($id),

			'business_analystRecords'=>$this->getBusiness_analystRecords($id),

			'key_userRecords' => $this->getKey_userRecords($id),

		));

	}


public function getKey_userRecords($parentID)

	{

		$dataProvider = new CActiveDataProvider('Key_User',array(

			'criteria'=>array(

				'with'=>array(

					'relKey_userFunctional_domain'=>array(

						'together'=>true,

						'alias'=>'key_user'

					),

				),	

				'condition'=>"key_user.FUNCTIONAL_DOMAIN_ID ='".$parentID."'",

			),

		));

		return $dataProvider;

	}

	

	public function getBusiness_analystRecords($parentID)

	{

		$dataProvider = new CActiveDataProvider('Business_analyst',array(

			'criteria'=>array(

				'with'=>array(

					'relBusiness_analystFunctional_domain'=>array(

						'together'=>true,

						'alias'=>'business_analyst'

					),

				),	

				'condition'=>"business_analyst.FUNCTIONAL_DOMAIN_ID ='".$parentID."'",

			),

		));

		return $dataProvider;

	}

if you have an idea, please, tell me. Am I just going to te wrong way?

Couple of problems:

In your CMenu widget instantiation you are forming the URLs incorrectly

This




array('label'=>'Key_user', 'url'=>array("/functional_domain/view&id=".$model->FUNCTIONAL_DOMAIN_ID.""),'valeur'=>"key_user"),



Should be:




array('label'=>'Key_user', 'url'=>array("/functional_domain/view", 'id'=>$model->FUNCTIONAL_DOMAIN_ID, 'valeur'=>"key_user"),



The “url” is passed through to CHtml::normalizeUrl, with the first parameter being the route and the other parameters being key-value pairs to encode within the URL. In your case ‘valeur’ was outside of the ‘url’ entry and so was being ignored.

Secondly, your controller action, actionView(), needs to not only retrieve the passed value of ‘valeur’ but also pass it onto your view. Something like this may work:




public function actionView($id)

{

   $httpRequest = Yii::app()->request;  // <----

   $first_parent_instance=Sdm::model()->find();

   

   $this->render('view',array(

      'model'=>$this->loadModel($id),

      'business_analystRecords'=>$this->getBusiness_analystRecords($id),

      'key_userRecords' => $this->getKey_userRecords($id),

      'valeur' => $httpRequest->getParam('valeur'),  // <----

   ));

}