Using dataProvider in views

Hi,

I am new to yii. I would like to use the dataProvider in one of the views, but when i try to call dataProvider i a getting error property not defined in the controller. Please help me.

Controller:

class MainpageController extends Controller

{

/**


 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning


 * using two-column layout. See 'protected/views/layouts/column2.php'.


 */


public $layout='//layouts/column2';





/**


 * Lists top 10 news.


 */


public function actionMpnews()


{


	$dataProvider=new CActiveDataProvider('Karnews',


		array('criteria'=>array(


				'condition'=>'category=0',


				'limit'=>'10',


			),


		)		


	);


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


		'dataProvider'=>$dataProvider,			


	));


}

}

View:

<?php

	echo CHtml::openTag('div',array('class'=&gt;'items')).&quot;&#092;n&quot;;


	&#036;data=&#036;this-&gt;dataProvider-&gt;getData();


			


	&#036;dispdata = array(


		array('image'=&gt;'images/karnataka.png', 


			'label'=&gt;'Karnataka', 


			'caption'=&gt;'Beautiful karnataka',


			'dataProvider'=&gt;&#036;dataProvider,


		));


	&#036;this-&gt;widget('bootstrap.widgets.BootCarousel', array(


		'items'=&gt;&#036;dispdata,			


		'events'=&gt;array(


			'slide'=&gt;&quot;js:function() { console.log('Carousel slide.'); }&quot;,


			'slid'=&gt;&quot;js:function() { console.log('Carousel slid.'); }&quot;,


		),


	)); 		


?&gt;

Error encountered:

Property "MainpageController.dataProvider" is not defined.

Please help me find a solution to use dataProvider instead of the ‘image’=>‘images/karnataka.png’.

Thank you.

You’re passing $dataProvider to your view, and then you use $this->dataProvider to access it, that’s wrong. All variables that are passed to a view can be accessed directly like $dataProvider.

So either change $dataProvider to $this->dataProvider your controller, OR (better option) use $dataProvider instead of $this->dataProvider in your view.

Thank you… Its working fine now…