Using dataProvider in views


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.


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',














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



	&#036;dispdata = array(



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



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



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

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




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…