As requested!
I am using yii-attachment-behavior for image uploads. You can see all the comments I put in the comments of the extension if you want to use this. I’m not going to post the model portion for the attachement-behavior you can go to the ext. to see it.
views/products/index.php
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$model->search(),
'itemView'=>'productgallery',
'template'=>'{pager}{items}<br/>{pager}',
'sortableAttributes'=>array(
'model', //don't get this confused this is my 'name' column
'company_id',
),
)); ?>
views/products/productgallery.php
<div class="productimg">
<?php echo CHtml::link('<img src="../'.$data->getAttachment('thumb').'" />', array('view', 'id'=>$data->product_id)); ?><br>
<div class="productimgdesc">
<h5>
<?php echo CHtml::link(CHtml::encode($data->company->name),array("companies/view","id"=>$data->company_id)); ?> <br>
<?php echo CHtml::link(CHtml::encode($data->model),array("products/view","id"=>$data->product_id)); ?>
</h5>
</div>
</div>
EDIT: I changed this becuase I didn't have a set way to ensure the products
image size would render the size i wanted them to every time to make sure my
pretty css didn't get jacked up + it's on auto (see the css). It will not keep
proportions but it will show them in a set size. I didn't want to relie on someone's server to have the proper image stuff installed.
The alt portion is just in case it can't find the image or default image it
it shows those words so I know where to look for the problem and it doesn't
leave the screen blank.
<div class="productimg">
<?php
$imagelink = '<img src="../'.$data->Attachment.'" style="width:270px;height:135px;" alt="Can\'t Find Product Image Directory" />';
echo CHtml::link($imagelink, array('view', 'id'=>$data->product_id)); ?><br>
<div class="productimgdesc">
<h5>
<?php echo CHtml::link(CHtml::encode($data->name),array("products/view","id"=>$data->product_id)); ?> <br/>
</h5>
</div>
</div>
models/products.php
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
...
return new CActiveDataProvider($this, array(
'pagination'=>array(
'pageSize'=>'10', //could put 1, 2, 3, 10, 20, 30, etc. however many you want to display per page.
),
'criteria'=>$criteria,
));
}
I’m letting the user select 10, 20, 30, 50 per page so my code if different but in your case if you only want 10 per page it is default so you can leave the portion above default gii. Or I believe that is how you make it preset value.
my theme/css/yourname.css
div.productimg
{
border:2px solid #f7f7f7;
height:auto;
width:auto;
float:left;
text-align:center;
margin:4px;
opacity:1.0;
}
div.productimg img
{
display:inline;
margin:3px;
border:10px solid #ffffff;
}
div.productimgdesc
{
text-align:center;
font-weight:normal;
border-top:2px solid #f7f7f7;
width:100%;
}
img:hover
{
opacity:.7;
filter:alpha(opacity=70); /* For IE8 and earlier */
}
Then of course you have to register the css in your theme/layouts/main.php
NOTE: My header and footer are in different files than the main.php so mine gets registered like this. Register yours how the other css are being registered at the top of your main.php. Or just add it to an existing css at the bottom.
<?php
$cs->registerCssFile($baseUrl.'/css/yourname.css');
protected/controllers/productscontroller.php
No edits
Maybe that will help your or maybe someone else good luck!