Beispiel #1
0
 /**
  * 其他分类需要显示在导航栏的新增方法
  * @param string $ctype 其他分类表标识 a:文章分类表,c:商品分类表
  * @param int $cid 其他表分类id
  * @return mixed
  */
 public function addData($ctype, $cid)
 {
     // 如果已经存在就不继续执行了
     if ($this->find()->where(['ctype' => $ctype, 'cid' => $cid])->one()) {
         return true;
     }
     switch ($ctype) {
         case 'a':
             // 文章分类
             $this->name = ArticleCat::findOne($cid)->cat_name;
             $this->url = '';
             // 前台还没有做,暂时空起
             break;
         case 'c':
             // 商品分类
             $this->name = Category::findOne($cid)->cat_name;
             $this->url = '';
             // 前台还没有做,暂时空起
             break;
         default:
             return false;
     }
     $this->ctype = $ctype;
     $this->cid = $cid;
     $this->type = 'middle';
     if ($this->insert(false)) {
         return true;
     }
     return false;
 }
 /**
  * Finds the ArticleCat model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ArticleCat the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ArticleCat::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #3
0
            <input type="submit" onclick="query('<?php 
echo Yii::$app->urlManager->createUrl(['article/index']);
?>
')" value=" 搜索 " class="button">

        </form>

    </div>

    <?php 
Pjax::begin();
?>
    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\CheckboxColumn', 'name' => 'id'], 'article_id', 'title', ['header' => Html::a('文章分类', 'javascript:void(0);'), 'content' => function ($model) {
    return ArticleCat::findOne($model->cat_id)->cat_name;
}], ['header' => Html::a('模型', 'javascript:void(0);'), 'content' => function ($model) {
    return (new ArticleCat())->modelArray[$model->model];
}], ['header' => Html::a('文章类型', 'javascript:void(0);'), 'content' => function ($model) {
    $typeList = ['0' => '普通', '1' => '置顶'];
    return $typeList[$model->article_type];
}], ['header' => Html::a('是否热门', 'javascript:void(0);'), 'content' => function ($model) {
    if ($model->is_hot == 1) {
        return Html::img('@web/image/yes.gif', ['onclick' => "setHot(this, {$model->article_id})", 'data-status' => 0]);
    }
    return Html::img('@web/image/no.gif', ['onclick' => "setHot(this, {$model->article_id})", 'data-status' => 1]);
}], ['header' => Html::a('是否显示', 'javascript:void(0);'), 'content' => function ($model) {
    if ($model->status == 1) {
        return Html::img('@web/image/yes.gif', ['onclick' => "setStatus(this, {$model->article_id})", 'data-status' => 0]);
    }
    return Html::img('@web/image/no.gif', ['onclick' => "setStatus(this, {$model->article_id})", 'data-status' => 1]);