zhoupenghui

zhoupenghui

这家伙有点懒,还没写个性签名!

  • 财富值870
  • 威望值120
  • 总积分2510

个人信息

  • public static function (){
       $rtn=Course::find()->select(['course_name','id'])->all();
        return $rtn;
    }
    
  • 回复了 的回答
    $model = new User();
    foreach($data as $attributes)
    {
         $_model = clone $model;
         $_model->setAttributes($attributes);
         $_model->save();
    }
    
    Yii::$app->db->createCommand()->batchInsert(UserModel::tableName(), ['user_id','username'], [
        ['1','test1'],
        ['2','test2'],
        ['3','test3'],   
    ])->execute();
    

    随机码?有点模糊,php 不是有一个生成随机数的函数吗?mt_rand($min,$max)

  • $model = new User();
    foreach($data as $attributes)
    {
         $_model = clone $model;
         $_model->setAttributes($attributes);
         $_model->save();
    }
    
    Yii::$app->db->createCommand()->batchInsert(UserModel::tableName(), ['user_id','username'], [
        ['1','test1'],
        ['2','test2'],
        ['3','test3'],   
    ])->execute();
    
  • 批量插入数据,还是已经有数据了,直接导入?

  • 这样写,试一试:

    控制器中: 
     public function actionList(){
            $list = Article::find()
                ->joinWith([
                  'articleCategory'=>function($query){  $query->select(['id','category'])},
                ])->asArray()
                ->all();
    
    
            var_dump($list);die();
    
            return $this->render('list',[
                'list'=>$list
            ]);
        }
    
    模型中: 
      public function getArticleCategory(){
            return $this->hasOne(ArticleCategory::className(),['id'=>'category_id']);
        }
    
    
  • 首先,要想使用这个配置,那么 "enableAutoLogin"必须为"true", 'httpOnly' => true 的意思是: cookie是否应该只通过HTTP协议访问, 属性设置为true,该cookie不会通过脚本语言访问,设为true的目的: 它可以有效地帮助通过XSS攻击,以减少身份盗窃

  • 赞了回答

    没图没真相。

  • 回复了 的回答

    你的意思是:每次页面刷新时,都要生成一个csrf吗?
    在控制器中:

    $csrfValue = Yii::$app->request->getCsrfToken();
    $cookies = Yii::$app->response->cookies;
    $cookies->add(new Cookie([
        'name' => '_csrf',
        'value' => $csrfValue,
        'expire' => $_SERVER['REQUEST_TIME'] + 86400,
    ]));
    

    怎么会?我测试了的呢,你把 name='_csrf'换个名字呢?或者没有引入Cookie,要 use yii\web\Cookie 哟;

  • 你的意思是:每次页面刷新时,都要生成一个csrf吗?
    在控制器中:

    $csrfValue = Yii::$app->request->getCsrfToken();
    $cookies = Yii::$app->response->cookies;
    $cookies->add(new Cookie([
        'name' => '_csrf',
        'value' => $csrfValue,
        'expire' => $_SERVER['REQUEST_TIME'] + 86400,
    ]));
    
  • 你点击进去看看,会跳转到MemberRelation数据模型中,说明返回的就是这个数据模型,也就是MemberRelation类

总监 等级规则
2510/5000
资料完整度
10/100
用户活跃度
0/100

Ta的关注

2

Ta的粉丝

3

Ta的访客

11