石头超人 2017-05-23 20:16:29 2209次浏览 0条评论 0 0 0

//根据分类查询文章

 $type = Type::find()->where(['type'=>'美容'])->one();
 $desc = $type->hasMany(Desc::className(),['type_id'=>'t_id'])->asArray()->all();   //也可以写到model层

//根据文章查询分类

 $art = Desc::find()->where(['title'=>'血友病吧被卖时间'])->one();
 $type = $art->hasOne(Type::className(),['t_id'=>'type_id'])->asArray()->one();

//跳到展示页面

 public function actionArt()
    {
        $model = new Ceshi();
        $type = Type::find()->asArray()->all();
        $data = array();

        foreach($type as $k=>$v)
        {
            $data[$v['t_id']] = $v['type'];
        }

        return $this->render('art_list',['model'=>$model,'data'=>$data]);
    }
    
    
    
 //删除
  		$id   = yii::$app->request->get('id');
        $desc = Desc::findOne($id);
        $res  = $desc->delete();
        
 //修改
 public function actionUp()
    {
        if($_POST)
        {
            $info          = yii::$app->request->post();
            $id = $info['Ceshi']['id'];
            $ss = Desc::findOne($id);
            $ss->title   = $info['Ceshi']['title'];
            $ss->type_id = $info['Ceshi']['type'];
            $ss->content = $info['Ceshi']['content'];
            $res = $ss->save();
            if($res)
            {
                return $this->redirect('?r=five/index');
            }

        }
        else
        {
            $id = yii::$app->request->get('id');
            $model = new Ceshi();
            $desc = Desc::find()->where(['id'=>$id])->asArray()->one();
            $type = Type::find()->asArray()->all();
            $data = array();
            foreach($type as $k=>$v)
            {
                $data[$v['t_id']] = $v['type'];
            }
            return $this->render('up',['model'=>$model,'desc'=>$desc,'data'=>$data]);
        }
    }
 //添加
 		$info       = yii::$app->request->post();   //接到的值
        $type       = new Type();                   //实例化type model
        $type->type = $info['type'];          		//
        $res        = $type->save();                 //添加
    没有找到数据。
您需要登录后才可以评论。登录 | 立即注册