public function actionView()
 {
     $id = (int) Yii::app()->request->getParam('id');
     $product = ProductModel::model()->findbyPk($id);
     if (empty($product)) {
         $this->forward("/index/error", true);
     }
     //log san pham
     $count = $product->view_count;
     $count = $count + 1;
     $product->view_count = $count;
     $product->save(false);
     //san pham tuong tu
     $limit = 8;
     $product_relate = ProductModel::model()->getProductRelate($id, $product->channel, $limit);
     //get list slider product
     $slider = ProductImgModel::model()->getSliderByProductId($id);
     $this->render('view', compact('product', 'product_relate', 'slider'));
 }
示例#2
0
                    <div class="items fll col-25 col-sm-3">
                        <div class="wrr-item">
                            <div class="wrr-item-main">
                                <div class="thumb thumb-hover">
                                    <?php 
    $link = !empty($product->des_link) ? $product->des_link : Yii::app()->createUrl('product/view', array('id' => $product->id, 'url_key' => $product->url_key));
    ?>
                                    <a title="<?php 
    echo $product->name;
    ?>
"  href="<?php 
    echo $link;
    ?>
">
                                        <?php 
    $product_img = ProductImgModel::model()->getOneImgByProductId($product->id);
    ?>
                                        <img width="100%" alt="<?php 
    echo $product->name;
    ?>
" src="<?php 
    echo $product_img[0]['img_url'];
    ?>
">
                                    </a>
                                </div>

                                <div class="wrr-item-content">
                                    <p class="item_main">
                                        <?php 
    echo Formatter::smartCut($product->name, 20);
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
 public function actionDeleteImg()
 {
     $product_id = Yii::app()->request->getParam('product_id');
     $img_id = Yii::app()->request->getParam('img_id');
     $product_img = ProductImgModel::model()->find('`product_id` = :product_id AND img_id = :img_id', array(':product_id' => $product_id, ':img_id' => $img_id));
     if (!empty($product_img)) {
         $delete = $product_img->delete();
         if ($delete) {
             $coverPath = ProductModel::model()->getCoverPath($product_id, $img_id);
             unlink($coverPath);
             $data = array('message' => 'Thành công', 'code' => 0);
         } else {
             $data = array('message' => 'Không thành công', 'code' => 1);
         }
     } else {
         $data = array('message' => 'Không tồn tại', 'code' => 2);
     }
     header("Content-type: application/json");
     echo json_encode($data);
     Yii::app()->end();
 }