Hi,
I would like to display more than 1 SQL record per row (at least 3) into a CGridView table.
example:
Ipods at google
is it possible ?
Hi,
I would like to display more than 1 SQL record per row (at least 3) into a CGridView table.
example:
Ipods at google
is it possible ?
You can use CListView instead.
example:
A list of albums (sorry, only in Japanese)
Could you provide more details ?
As softarks says, using "[color=#1C2837][size=2]You can use CListView instead[/size][/color]", because CListView admites the "personalize" your row.
at first step you need to create a file named (as an example) "_myrow.php",
this file ("_myrow.php") has your Row definition, you can see a more detailed exampled in yii documentation:
http://www.yiiframework.com/doc/api/1.1/CListView
as an example, suppose that "_myrow.php" has this dummy code:
--start of _myrow.php--
<div>
this is my row, at model ID number: <?php $data->myrowID; ?> // $DATA is your "pointer" to your current model instance for the current row
and my name is: <?php $data->name;?>
</div>
--end of _myrow.php--
when your datasource iterates on CListView, then it replies the content of "_myrow.php" for each row on your data set,
suppose that your model data comes from this JSON sample array: “[{myrowID:1, name:‘xx’}, {myrowID:2, name: ‘zz’}]”
when you creates a dataprovider for this model, then CListView would creates this output (using the example at top):
<div>
this is my row, at model ID number: 1
and my name is: XX
</div>
<div>
this is my row, at model ID number: 2
and my name is: ZZ
</div>
hope it help you.
looking at your desired example: Ipods at google
you need to create a view file for your existing model,
this view (ipods at google) can be made using CListView,
I suppose that you have your model definition very clear,
IN YOUR MODEL:
MyPhones.php is your model,
must have:
public static function getDataProvider($pageSize=20,$extraCriteria=null){
$c1 = $extraCriteria == null ? "" : $extraCriteria;
return new CActiveDataProvider(self::model(), array(
'criteria'=>array(
'condition'=>$c1,
),
'pagination'=>array(
'pageSize'=>$pageSize,
),
));
}
In Controller:
public function actionListPhonesAsGoogleDoes(){
$dataSet = MyPhones::getDataProvider(20," articleid='iphones' ");
$this->render("myphonesasgoogledoes" , array('dataset'=>$dataSet));
}
In View:
VIEW#1 views/myphones/myphonesasgoogledoes.php
$this->widget('zii.widgets.CListView',
array(
'dataProvider'=>$dataSet,
'itemView'=>'_myphones',
'sortableAttributes'=>array(
'title',
'phonemodel'=>'Phone Model', // it is not relevant for this example code
),));
VIEW#2 views/myphones/_myphone.php (note the "[font=“monospace”]‘itemView’=>’_myphones’ in master view file[/font])
<div class='xxxphone'>
<img src='<?php echo $data->phoneimageurl;?>' >
<span><?php echo $data->phonepublicname;?></span>
</div>
c) a css class file that defines your view:
myphonesasgoogledoes.css:
div.xxxphone {
border: 1px solid gray;
float: left;
overflow: auto;
text-align: center;
margin: 10px;
padding: 10px;
}
div.xxxphone img {
width: 100px;
height: 100px;
}
div.xxxphone span {
color: red;
}
Ok, thanks !