madshov
            (Mo)
          
          
          
              
              
          1
          
         
        
          Hello,
I am very new the Yii, so my question is of the probably of the simple kind:
Basically I want to know how i can create a list of news on my frontpage. My site controller looks like this:
$criteria = new CDbCriteria(array(
                'order' => 'date DESC',
                ));
                $conditions = array();
                $conditions[] = 'cat=:cat';
                $conditions[] = 'expires_time>:expires_time';
                $criteria->condition = implode(' AND ', $conditions);
                $criteria->params=array(':cat' => $cat['cat'], ':expires_time' => time(),);
                $dataProvider=new CActiveDataProvider('News', array( 'criteria' => $criteria, 'pagination' => false ));
                $this->render('index',array('dataProvider' => $dataProvider,));
This renders the index file in my site view
My index file looks like the following:
<div id="content">
        <div class="items">
        <?
                $this->widget('zii.widgets.CListView', array('dataProvider'=>$dataProvider, 'itemView'=>'_view', 'summaryText' =>false ));
        ?>
        </div><!-- div class items -->
</div> <!-- div id content -->
But I would like to use the itemview of my news mvc instead. I hope it makes sense
Thanks in advance
         
        
          
        
           
           
           
         
         
            
            
          
       
      
        
          
          
            zaccaria
            (Matteo Falsitta)
          
          
          
              
              
          2
          
         
        
          You can simply create a new view file in the views/controllerId/ folder named as you wish, for example _newsMVC.
Then:
 $this->widget('zii.widgets.CListView', array('dataProvider'=>$dataProvider, 'itemView'=>'_newsMVC', 'summaryText' =>false ));
P.s: welcome to the forum
         
        
        
           
           
           
         
         
            
            
          
       
      
        
          
          
            madshov
            (Mo)
          
          
          
              
              
          3
          
         
        
          Hi zaccaria and everone else reading,
Thanks for you reply!!
If my view/index.php is in the site folder, can I on some way use an itemView-template from another controllerid folder?
My listview in views/site/index.php
$this->widget('zii.widgets.CListView', array('dataProvider'=>$dataProvider, 'itemView'=>'news', 'summaryText' =>false ));
This call needs my news.php to be placed in views/site/ also.
Or can I tell my render function in SiteController.php to use an index.php file i another controllerid folder?
My call to render in SiteController.php (frontpage):
$this->render('index',array('dataProvider' => $dataProvider,));
Or would this break the principles in mvc and the framework.
Thanks again
/Mads
         
        
        
           
           
           
         
         
            
            
          
       
      
        
          
          
            jkofsky
            (Jkofsky)
          
          
          
              
              
          4
          
         
        
          
Don’t know if it breaks MVC but…
$this->render('controllerid/index',array('dataProvider' => $dataProvider,));
or
$this->render('//controllerid/index',array('dataProvider' => $dataProvider,));
         
        
        
           
           
           
         
         
            
            
          
       
      
        
          
          
            nickcv
            (N Puddu)
          
          
          
              
              
          5
          
         
        
          jkofsky solution works, but use renderPartial
ciao