Esempio n. 1
0
<?php

use common\models\Image;
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model common\models\Product */
$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend/product', 'Products'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
$image_models = Image::findAll(['model_id' => $model->id]);
$images = null;
foreach ($image_models as $image) {
    $images .= Html::img(Yii::$app->urlManagerFrontEnd->baseUrl . '/uploads/product/' . $model->id . '/' . $image->id . '.jpg', ['width' => '200px', 'class' => 'img-thumbnail']);
}
?>
<div class="product-view">

    <h1 class="page-header">
        <?php 
echo Html::encode($this->title);
?>
        <div class="btn-group pull-right">
            <?php 
echo Html::a('<span class="glyphicon glyphicon-eye-open"></span>', Yii::$app->urlManagerFrontEnd->createUrl(['catalog/view', 'slug' => $model->slug, 'category' => $model->category->slug]), ['class' => 'btn btn-success', 'target' => '_blank', 'data-toggle' => 'tooltip', 'title' => Yii::t('backend/product', 'View on site')]);
?>
            <?php 
echo Html::a('<span class="glyphicon glyphicon-pencil"></span>', ['update', 'id' => $model->id], ['class' => 'btn btn-primary', 'data-toggle' => 'tooltip', 'title' => Yii::t('backend/product', 'Update')]);
?>
            <?php 
echo Html::a('<span class="glyphicon glyphicon-trash"></span>', ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'title' => Yii::t('backend/product', 'Delete'), 'data' => ['toggle' => 'tooltip', 'confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'), 'method' => 'post']]);
Esempio n. 2
0
 /**
  * Updates an existing Product model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         $model->image = UploadedFile::getInstance($model, 'image');
         $model->images = UploadedFile::getInstances($model, 'images');
         if ($model->validate() && $model->save()) {
             $dir = Yii::getAlias('@frontend/web/uploads/product/' . $model->id);
             if ($model->image) {
                 $model->image->saveAs($dir . '/main.jpg');
             }
             if ($model->images) {
                 $imageModels = Image::findAll(['model_id' => $model->id]);
                 if ($imageModels) {
                     foreach ($imageModels as $image) {
                         $file = $dir . '/' . $image->id . '.jpg';
                         if (file_exists($file)) {
                             unlink($file);
                         }
                         $image->delete();
                     }
                 }
                 foreach ($model->images as $image) {
                     $imageModel = new Image();
                     $imageModel->model_id = $model->id;
                     $imageModel->save();
                     $image->saveAs($dir . '/' . $imageModel->id . '.jpg');
                 }
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     }
     return $this->render('update', ['model' => $model]);
 }
Esempio n. 3
0
/* @var $this yii\web\View */
/* @var $model common\models\Product */
$this->title = $model->name . ' - ' . $model->category->name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('frontend/catalog', 'Catalog'), 'url' => ['catalog/index']];
if ($model->category->parent) {
    $this->title .= ' - ' . $model->category->parent->name;
    $this->params['breadcrumbs'][] = ['label' => $model->category->parent->name, 'url' => ['catalog/category', 'category' => $model->category->parent->slug]];
}
$this->params['breadcrumbs'][] = ['label' => $model->category->name, 'url' => ['catalog/category', 'category' => $model->category->slug]];
$this->params['breadcrumbs'][] = $model->name;
// Meta tags
$this->registerMetaTag(['name' => 'description', 'content' => $model->meta_description]);
$this->registerMetaTag(['name' => 'keywords', 'content' => $model->meta_keywords]);
// Gallery images
$galleryItems[] = ['src' => Yii::$app->urlManager->baseUrl . '/uploads/product/' . $model->id . '/main.jpg', 'options' => ['title' => $model->name]];
foreach (Image::findAll(['model_id' => $model->id]) as $image) {
    $galleryItems[] = ['src' => Yii::$app->urlManager->baseUrl . '/uploads/product/' . $model->id . '/' . $image->id . '.jpg', 'options' => ['title' => $model->name]];
}
?>

<div class="row">
    <div class="col-sm-6">
        <?php 
echo Gallery::widget(['items' => $galleryItems, 'id' => 'product-gallery-links']);
?>
    </div>

    <div class="col-sm-6">
        <h1 class="product-header">
            <?php 
echo $model->name;
 public function actionIndex($tn, $id)
 {
     $model = Image::findAll(['table_name' => $tn, 'table_id' => $tid]);
     return $this->render('index', ['model' => $model]);
 }