Yii Framework Forum: How To Access Modal Variables In Index View (Actionindex) - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How To Access Modal Variables In Index View (Actionindex) Rate Topic: -----

#1 User is offline   danielT 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 14-June 13

Posted 15 June 2013 - 12:46 AM

I am new to yii and am working through the book Web Application Development with Yii and PHP to create a project tracking system.

The modals, controllers and views (CRUD functionality) have been created with the Gii tool.

The IssueController renders a CActiveDataProvider for the index view. The index view displays a couple of menu items and then displays the CActiveDataProvider in a CListView widget.

What I would like to do is include a modal variable in the menu items in the index view but the modal is not defined. So I am wondering how you would go about defining the modal. I assume that it needs to be defined in the IssueContoller actionIndex and passed through to the index view?

I am sure this is very obvious but I am still learning Yii and the fundamentals of OOP. Any help would be greatly appreciated.

IssueController actionIndex
public function actionIndex()
	{
		$dataProvider=new CActiveDataProvider('Issue', array(
			'criteria'=>array(
				'condition'=>'project_id=:projectId',
				'params'=>array(':projectId'=>$this->_project->id),
				),
		));
		$this->render('index',array(
			'dataProvider'=>$dataProvider,
		));
	}


index view
<?php
/* @var $this IssueController */
/* @var $dataProvider CActiveDataProvider */

$this->breadcrumbs=array(
	'Issues',
);

$this->menu=array(
	array('label'=>'Create Issue', 'url'=>array('create')),
	array('label'=>'Manage Issue', 'url'=>array('admin')),
);
echo $dataProvider->product_id;
?>

<h1>Issues</h1>

<?php $this->widget('zii.widgets.CListView', array(
	'dataProvider'=>$dataProvider,
	'itemView'=>'_view',
)); ?>

0

#2 User is offline   danielT 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 14-June 13

Posted 15 June 2013 - 06:39 AM

I worked out a couple of ways of doing it and the one I went with is below.
public function actionIndex($pid)
	{
		$dataProvider=new CActiveDataProvider('Issue', array(
			'criteria'=>array(
				'condition'=>'project_id=:projectId',
				'params'=>array(':projectId'=>$this->_project->id),
				),
		));
		$this->render('index',array(
			'dataProvider'=>$dataProvider,
			'model'=>$this->loadProject($pid),
		));
	}


I believe the $pid parameter is being populated by automatic action parameter binding as detailed here.

loadProject is a method in the IssueController that returns the project data model based on the primary key given.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users