Yii Framework Forum: Two Dataproviders On A View With Render And Renderpartial - Yii Framework Forum

Jump to content

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

Two Dataproviders On A View With Render And Renderpartial

#1 User is offline   xexulongo 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 19-July 13

Posted 19 September 2013 - 06:20 PM

I'm too newbie on Yii apps and need some help. First of all, sorry for my bad english.

After following the yii blog tutorial I tried to make it better with some new features. One of them it's stand out some news (the most recent). I want to show on top stand out news and after that all news. To do that I have to render two views on index and create two $dataProviders (these two views use the same model Post but have particular $criteria, pagination, etc). When i call renderPartial and render functions it works but seems that something breaks and all the accent marks are shown as part of code.

That's my actionIndex:
public function actionIndex()
	{
		$criteriaPost=new CDbCriteria(array(
        'condition'=>'status='.Post::STATUS_PUBLICADO,
        'order'=>'update_time DESC',
        'with'=>'commentCount',
    	));
	    if(isset($_GET['tag']))
	        $criteria->addSearchCondition('tags',$_GET['tag']);
	 
	    $dataProviderPost=new CActiveDataProvider('Post', array(
	        'pagination'=>array(
	            'pageSize'=>5,
	        ),
	        'criteria'=>$criteriaPost,
	    ));

	    $criteriaDestacados=new CDbCriteria(array(
        'condition'=>'status='.Post::STATUS_PUBLICADO,
        'order'=>'update_time DESC',
        'with'=>'commentCount',
        'offset' => 0,
        'limit'=>6,

    	));
	    if(isset($_GET['tag']))
	        $criteria->addSearchCondition('tags',$_GET['tag']);
	 
	    $dataProviderDestacados=new CActiveDataProvider('Post', array(
	    	'pagination' => false,

	        'criteria'=>$criteriaDestacados,
	    ));

	  	$this->pageTitle = "SVGA - Noticias"; // It could be something from DB or...whatever
	   $this->renderPartial('destacados',array(
	   	'dataProvider1'=>$dataProviderDestacados,
	   	));
	   $this->render('index',array(
        'dataProvider2'=>$dataProviderPost,
    	));
	}


Index:
<?php $this->widget('zii.widgets.CListView', array(
	'dataProvider'=>$dataProvider2,
	'itemView'=>'_view',
	'sortableAttributes'=>array(
          'title',
          'create_time'=>'Fecha',
      ),
));
?>


Destacados(outstanding):
<?php $this->widget('zii.widgets.CListView', array(
	'dataProvider'=>$dataProvider1,
	'summaryText'=>'', 
	'itemView'=>'_destacadosview',
));
?>


Somebody know what's wrong?
0

#2 User is offline   chamara 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 47
  • Joined: 05-June 13
  • Location:srilanka

Posted 19 September 2013 - 09:29 PM

use
$this->renderPartial('destacados',array(
'dataProvider1'=>$dataProviderDestacados,
));

in index file and put another data provider to index action


$this->render('index',array(
'dataProvider2'=>$dataProviderPost,
'dataProvider2'=>$dataProviderPost,
));

try form this
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