toGoods() public static method

public static toGoods ( $name )
 public function actionDetail($id)
 {
     $model = Goods::findOne(['id' => $id, 'status' => Goods::STATUS_NORMAL]);
     if (!$model) {
         throw new NotFoundHttpException('未找到该商品');
     }
     $output = ['status' => 'ok', 'name' => $model->name, 'price' => $model->price, 'surplus' => $model->surplus, 'description' => '【笑e购】' . $model->description, 'cart' => Yii::$app->user->isGuest ? 0 : Yii::$app->user->identity->getCartGoodsQuantity($id), 'image' => $model->images ? Url::toGoods($model->images[0]->name) : Yii::$app->params['goods.defaultImageUrl']];
     Yii::$app->response->format = Response::FORMAT_JSON;
     return $output;
 }
Beispiel #2
0
<?php

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use kartik\file\FileInput;
use common\models\Goods;
use common\helpers\Url;
$preview = [];
foreach ($model->images as $img) {
    $preview[] = Html::img(Url::toGoods($img->name), ['class' => 'file-preview-image']);
}
$this->title = '更新商品图片';
?>
<div class="row">
    <div class="col-lg-6">
    <?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>
        <?php 
echo $form->field($model, 'name')->textInput(['disabled' => true]);
?>
        <?php 
echo $form->field($model, 'photos[]')->widget(FileInput::className(), ['options' => ['accept' => 'image/*', 'multiple' => true], 'pluginOptions' => ['showUpload' => false, 'browseLabel' => '选择照片', 'removeLabel' => '删除', 'initialPreview' => $preview]]);
?>
        <div class="form-group">
            <?php 
echo Html::submitButton('<i class="fa fa-floppy-o"></i> 保存', ['class' => 'btn btn-primary']);
?>
            <?php 
echo Html::a('返回商品详情', ['/goods/update', 'id' => $model->id], ['class' => 'text-warning']);
?>