zoukankan      html  css  js  c++  java
  • yii中接收微信传过来的json数据

    //控制器
    <?php namespace frontendcontrollers; use frontendmodelsUser; use yii; use yiiwebController; 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 frontendmodels;
    use yii;
    use yiiaseModel;
    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;
            }
        }
    }
    你所浪费的今天是那些死去的人所奢望的明天,你所厌恶的现在是未来的你所回不去的曾经。
  • 相关阅读:
    c++:函数模板
    1084 外观数列
    1083 是否存在相等的差
    1082 射击比赛
    1081 检查密码
    1080 MOOC期终成绩
    1079 延迟的回文数
    1078 字符串压缩与解压
    1077 互评成绩计算
    1076 Wifi密码
  • 原文地址:https://www.cnblogs.com/stj123/p/10518747.html
Copyright © 2011-2022 走看看