yii中接收微信传过来的json数据

//控制器
<?php namespace frontend\controllers; use frontend\models\User; use yii; use yii\web\Controller; class ContController extends Controller { public $enableCsrfValidation = false; //用户注册 public function actionUser() { //接收json数据 $a=file_get_contents("php://input"); $aa=json_decode($a,true); $last=User::add($aa); if($last) { return "添加成功"; } else { return "添加失败"; } } }
//模型层
<?php
namespace frontend\models;
use yii;
use yii\base\Model;
class User extends Model
{
    //用户添加
    public static function add(array &$data)
    {
      //  return $data['name'];
        $a=Yii::$app->db->createCommand()->insert('user', [
            'name' => $data['name'],
            'age' => $data['age'],
            'se' => $data['se'],
            'email' => $data['email'],
            'tell' => $data['tell'],
            'pwd' => $data['pwd'],
        ])->execute();
        if($a)
        {
            return true;
        }else{
            return false;
        }
    }
}

 

posted @ 2019-03-12 18:53  PHP小媛  阅读(583)  评论(0编辑  收藏  举报