首页 > 其他 > 详细

yii2.0 的 数据的增

时间:2016-03-15 18:37:16      阅读:169      评论:0      收藏:0      [点我收藏+]

增加数据

    /**
     * 添加数据  controller 层
     */

 

  //引入对应的model类

  use app\models\About;

  //定义对应的方法固定的actionxxxx -- 增加数据

  public function actionAdd(){

        //判断是否是提交过来的数据

        $request = Yii::$app->request;

        if ($request->isPost){

                //实力话model

            $model_about = new About();

            $model_ok = $model_about->adddata();

            if ($model_ok) {

                //添加成功 跳转到 index 方法
                
                return $this->redirect(Url::toRoute(‘/about/index‘));

                exit;

            }
        }

        //添加数据

        return $this->renderPartial(‘add‘);
    }

 

    /**
     * 添加数据  models层
     */

    public function adddata(){

            //接收数据

        $this->about_name = trim($_POST[‘about_name‘]);
        $this->about_link = trim($_POST[‘about_link‘]);
        $this->about_num = trim($_POST[‘about_num‘]);
        $this->about_show = trim($_POST[‘about_show‘]);
        $this->about_status = trim($_POST[‘about_status‘]);        

        return $this->save();
    }

yii2.0 的 数据的增

原文:http://www.cnblogs.com/laowenBlog/p/5280418.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!