zhoupenghui
- zhoupenghui 回答了问题 快速调用数据库的方法?
public static function (){ $rtn=Course::find()->select(['course_name','id'])->all(); return $rtn; }
- zhoupenghui 回复了 zhoupenghui 的回答
$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();
批量插入数据,还是已经有数据了,直接导入?
- zhoupenghui 回答了问题 如何做关联查询?
这样写,试一试:
控制器中: 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攻击,以减少身份盗窃- zhoupenghui 赞了回答
没图没真相。
- zhoupenghui 回复了 zhoupenghui 的回答
你的意思是:每次页面刷新时,都要生成一个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 哟;
- zhoupenghui 回答了问题 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, ]));
- zhoupenghui 回答了问题 请问一下这个返回的是型
你点击进去看看,会跳转到MemberRelation数据模型中,说明返回的就是这个数据模型,也就是MemberRelation类