How to create a CListView

Hello everybody,

yesterday I’ve started creating my first web application using Yii. Basically I’ve to do I little work using php and mysql and I’ve decided to use Yii in order to learn a new framework :)

I’ve just a question because I’ve to show a list of file and I think that using a CListView is an elegant way to do it.

The only problem is that I didn’t figure out how to let this work. On the class reference I used the example just to see how it works:


$dataProvider=new CActiveDataProvider('Post');


$this->widget('zii.widgets.CListView', array(

    'dataProvider'=>$dataProvider,

    'itemView'=>'_post',   // refers to the partial view named '_post'

    'sortableAttributes'=>array(

        'title',

        'create_time'=>'Post Time',

    ),

));

I think that Post should be a class of the Model, therefore I used one of mine ("Utente") and then the the partial view I assumed that is the view I used mine that is "Home".


<?php 


        	$dataProvider=new CActiveDataProvider('Utente');


$this->widget('zii.widgets.CListView', array(

    'dataProvider'=>$dataProvider,

    'itemView'=>'home',   // refers to the partial view named '_post'

    'sortableAttributes'=>array(

        'title',

        'create_time'=>'Post Time',

    ),

));

?>



I put this code in the view /webapp/protected/view/site/home.php

But what I get is just a blank page and this php error:

[01-Sep-2011 22:17:02] PHP Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 40961 bytes) in /Users/giuliovalente/Documents/QBT/Gemini/framework/web/CBaseController.php on line 117

Does anybody where I did wrong?

Thank in advance for any help.

As a starting point you should have a closer look at the index.php and _view.php files in the Gii-generated view code. The appropriate directory is <your_app>/protected/<your-controller>/view.

/Tommy

Mmmh… Ok, I’ve started from the starting web app with the login as example… at the moment I have ‘<my_app>/protected/views/site/index.php’ that is the current page for the login but in the ‘site’ folders I have not the _view.php files… I’ve a ‘_view.php’ files in ‘<my_app>/protected/views/utente/_view.php’, but I assume it was created when I create the CRUD for the ‘Utente’ model, which is a table of my db.

I don’t catch what I should provide as parameter in the constructor of CActiveDataProvider (a Model right?) and what is the itemView…

Any help?

Thank you :)

Yes, examine the generated CRUD code, it has a working CListView.

The name of a model class will be fine as parameter for constructing a CActiveDataProvider returning all records in the models table.

In the itemView property you declare the subview (_view.php) used to display the attributes from each model instance (record).

/Tommy