예제 #1
0
 /**
  * Finds the Ad model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Ad the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Ad::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Ad::find()->alive();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => [], 'sort' => ['defaultOrder' => ['order' => SORT_ASC]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'ad_type_id' => $this->ad_type_id, 'order' => $this->order, 'status' => $this->status, 'updated_at' => $this->updated_at, 'created_at' => $this->created_at]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'mode', $this->mode])->andFilterWhere(['like', 'pic_url', $this->pic_url])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'link_url', $this->link_url]);
     return $dataProvider;
 }
예제 #3
0
 /**
  * 首页
  * @return string
  */
 public function actionIndex()
 {
     $columns = Column::find()->where(['type' => Column::CMS_TYPE_LIST])->active()->orderBy('order ASC')->all();
     //关于我们单页
     $about = Column::find()->where(['short_code' => 'about-brief'])->active()->one();
     //首页主广告
     $mainAdType = AdType::find()->where(['short_code' => 'home_main'])->active()->one();
     //in查询
     $mainAds = $mainAdType->getAd()->active()->orderBy('order ASC')->all();
     //底部广告
     $adBottom = Ad::find()->where(['short_code' => 'home_bottom'])->active()->one();
     //搬家现场,推荐
     $scenes = Img::find()->select(Img::tableName() . '.*')->where(['like', Img::tableName() . '.flag', 'c'])->joinWith(['column' => function ($query) {
         $query->where([Column::tableName() . '.short_code' => 'xianchang']);
     }])->active()->all();
     //搬家现场推荐
     return $this->render('index', ['columns' => $columns, 'about' => $about, 'mainAdType' => $mainAdType, 'mainAds' => $mainAds, 'adBottom' => $adBottom, 'scenes' => $scenes]);
 }
예제 #4
0
파일: SideAd.php 프로젝트: jorry2008/turen
 public function run()
 {
     $uploadPath = Yii::getAlias('@backend') . '/web/upload';
     $model = Ad::findOne(['short_code' => $this->short_code]);
     if ($model && is_file($uploadPath . '/' . $model->pic_url)) {
         list($width, $height, $type, $attr) = getimagesize($uploadPath . '/' . $model->pic_url);
         if ($this->height && $this->width) {
             //nothing
         } elseif ($this->height) {
             $this->width = floor($this->height * $width / $height);
         } elseif ($this->width) {
             $this->height = floor($this->width * $height / $width);
         }
         $img = General::showImg($model->pic_url, 'c', $model->title, 'px', $this->width, $this->height);
         return $this->render('side-ad', ['model' => $model, 'img' => $img]);
     } else {
         return '';
     }
 }
예제 #5
0
파일: _form.php 프로젝트: jorry2008/turen
}
?>

<div class="row cms-ad-form">
    <div class="col-md-12">
        <?php 
//广泛布局
$form = ActiveForm::begin(['layout' => 'horizontal', 'fieldConfig' => ['template' => "{label} {beginWrapper} {input} {hint} {error} {endWrapper}", 'horizontalCssClasses' => ['label' => 'col-sm-2', 'offset' => 'col-sm-offset-2', 'wrapper' => 'col-sm-8', 'error' => '', 'hint' => '']]]);
?>
    
        <?php 
echo $form->field($model, 'ad_type_id')->dropDownList(ArrayHelper::map(AdType::find()->alive()->all(), 'id', 'name'));
?>
        
        <?php 
echo $form->field($model, 'mode')->dropDownList(Ad::getAdMode());
?>

	    <?php 
echo $form->field($model, 'title')->textInput(['maxlength' => true]);
?>
	    
	    <?php 
echo $form->field($model, 'short_code')->textInput(['maxlength' => true]);
?>
	    
	    <?php 
echo $form->field($model, 'pic_url')->hint('<i class="fa fa-info-circle"></i> ' . Yii::t('fileinput', 'Note: Limit upload one picture.'))->widget(FileInput::classname(), ['options' => ['accept' => 'image/*', 'multiple' => false], 'pluginOptions' => ['uploadUrl' => Url::to(['/cms/ad/file-upload']), 'uploadAsync' => true, 'initialPreview' => General::showImages($model->pic_url), 'initialPreviewConfig' => General::showLinks($model->pic_url, 'pic_url', 'ad', '/cms/ad/file-upload'), 'previewFileType' => 'any', 'overwriteInitial' => true, 'maxFileSize' => Yii::$app->params['config']['config_pic_size'], 'allowedFileExtensions' => explode(',', Yii::$app->params['config']['config_pic_extension']), 'allowedFileTypes' => ['image'], 'maxFileCount' => 1, 'uploadExtraData' => ['dir' => 'ad', 'name' => 'Ad[pic_url]', 'route' => '/cms/ad/file-upload', 'field' => 'pic_url']]]);
?>
	    
	    <?php 
예제 #6
0
파일: index.php 프로젝트: jorry2008/turen
echo Html::a(Yii::t('cms', 'Create Ad'), ['create'], ['class' => 'btn btn-success']);
?>
                        </p>
                     -->
            		<?php 
Pjax::begin();
?>
					<?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'options' => ['class' => 'grid-view box-body table-responsive no-padding'], 'tableOptions' => ['class' => 'table table-hover table-striped table-bordered'], 'headerRowOptions' => [], 'footerRowOptions' => [], 'showHeader' => true, 'showFooter' => false, 'layout' => "{summary}\n{errors}\n{items}\n{pager}", 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'title', 'format' => 'raw', 'value' => function ($model) {
    $length = Yii::$app->params['config']['config_site_title_length'];
    $title = StringHelper::truncate($model->title, $length);
    return Html::a($title, ['update', 'id' => $model->id], ['data-pjax' => '0']);
}], 'short_code', ['attribute' => 'ad_type_id', 'filter' => ArrayHelper::map(AdType::find()->alive()->all(), 'id', 'name'), 'filterInputOptions' => ['class' => 'form-control', 'id' => null, 'prompt' => Yii::t('common', 'All')], 'value' => function ($model) {
    return $model->adType->name;
}], ['attribute' => 'mode', 'format' => 'raw', 'filter' => Ad::getAdMode(), 'filterInputOptions' => ['class' => 'form-control', 'id' => null, 'prompt' => Yii::t('common', 'All')], 'value' => function ($model) {
    $modes = Ad::getAdMode();
    return empty($modes[$model->mode]) ? '' : $modes[$model->mode];
}], ['attribute' => 'order', 'format' => 'raw', 'value' => function ($model) {
    return Html::activeTextInput($model, 'order', ['style' => 'width:50px', 'data-id' => $model->id, 'id' => '', 'class' => 'cms-order']);
}], ['attribute' => 'status', 'format' => 'html', 'filter' => [Ad::STATUS_YES => Yii::t('cms', 'Yes'), Ad::STATUS_NO => Yii::t('cms', 'No')], 'filterInputOptions' => ['class' => 'form-control', 'id' => null, 'prompt' => Yii::t('common', 'All')], 'value' => function ($model) {
    $on = Html::a('<small class="label bg-green">' . Yii::t('common', 'Yes') . '</small>', ['switch-status', 'id' => $model->id], ['title' => Yii::t('cms', 'Update Status'), 'data-pjax' => '0']);
    $off = Html::a('<small class="label bg-red">' . Yii::t('common', 'No') . '</small>', ['switch-status', 'id' => $model->id], ['title' => Yii::t('cms', 'Update Status'), 'data-pjax' => '0']);
    return $model->status ? $on : $off;
}], 'created_at:datetime', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{delete}', 'header' => Yii::t('common', 'Opration')]]]);
?>
					<?php 
Pjax::end();
?>
     
                </div>
                
예제 #7
0
파일: AdType.php 프로젝트: jorry2008/turen
 /**
  * 一对多
  */
 public function getAd()
 {
     return $this->hasMany(Ad::className(), ['ad_type_id' => 'id']);
 }