ListView

Hello

I am working on a blog type site, and i would like to list out all the posts in my Post table.

like: Title1(Content1)

  Title2(Content2)


  Title3(Content3)

and so on maybe arrange them in a table or with divs. And i would like to know if is this possible without using the ‘zii.widgets.CListView’ widget. If yes, can some one tell me how, or where can i read about it?

Thank you.

bump , any suggestions please?

Hi Toma,

You can just loop through the retrieved posts.




$models = Post::model()->findAll($some_condition);

foreach($models as $model)

{

    echo '<div>';

    echo CHtml::encode($model->title) . '(' . CHtml::encode($model->content) . ')';

    echo '</div>';

}



Or you can use renderPartial.




$models = Post::model()->findAll($some_condition);

foreach($models as $model)

{

    $this->renderPartial('_view', array('model'=>$model));

}

...

// _view.php

<div>

<?php echo CHtml::encode($model->title) . '(' . CHtml::encode($model->content) . ')'; ?>

</div>



But why do you want to do without CListView? What’s wrong with it?

thank you. I would like to costumize it with my own style. Dont like the way the listview shows it.

You can customize the look of CListView by modifying the partial view that "itemView" property refers to.

As you know, CRUD generator of gii can make several pages for a model.

I would start by letting gii generate CRUD pages for "Post" model, and will pick up "index" page that uses a CListView.

It’s true that the generated “index” page is, say, very poor looking.

But you can easily modify "_view.php" to satisfy your taste.