摘要: 用ajax请求还是用命令行CURL请求总是会得到http400:Bad Request的错误,而如果用Web网页方式GET访问(去除verbFilter的POST限制),是正常的,是CSRF验证的原因因为Web网页访问的时候form表单中会有对应的一个隐藏input:_csrf进行了验证才可以正常进... 阅读全文
posted @ 2015-10-16 15:04 慕尘 阅读(210) 评论(0) 推荐(0) 编辑
摘要: Yii2 RBAC用到的四张auth表位于 vendor/yiisoft/yii2/rbac/migration文件夹里面,可以用migration生成yii migrate --migrationPath=@yii/rbac/migrations/或者使用下面的sql语句CREATE TABLE ... 阅读全文
posted @ 2015-10-13 14:05 慕尘 阅读(1391) 评论(0) 推荐(0) 编辑
摘要: Rbac 支持两种类,PhpManager(基于文件的) 和 DbManager(基于数据库的)权限:就是指用户是否可以执行哪些操作角色:就是上面说的一组操作的集合,角色还可以继承在Yii2.0中yii\rbac: Item为角色或者权限的基类,其中用字段type来标识yii\rbac: Role为... 阅读全文
posted @ 2015-10-12 15:21 慕尘 阅读(1927) 评论(0) 推荐(0) 编辑
摘要: JQuery中编码var url = 'folder/index.html?param=#23dd&noob=yes'; var encodedUrl = encodeURIComponent(url);解码var url = 'folder%2Findex.html%3Fparam%3D%2323... 阅读全文
posted @ 2015-10-10 11:29 慕尘 阅读(212) 评论(1) 推荐(0) 编辑
摘要: yii2的url域名/index.php?r=site%2Findex实际为域名/index.php?r=site/index可以美化下可以在main.php中配置'components' => [ …… 'urlManager'=> [ 'enabl... 阅读全文
posted @ 2015-10-09 11:11 慕尘 阅读(261) 评论(0) 推荐(0) 编辑
摘要: 显示信息提示用户时,可以用setFlash,hasFlash,getFlashfunction actionOk(){ Yii::app()->user->setFlash('success', 'Everything went fine!'); $this->redir... 阅读全文
posted @ 2015-09-30 00:08 慕尘 阅读(612) 评论(0) 推荐(0) 编辑
摘要: YII2对密码加密生成的结果是不同的,即用相同的初始密码在不同时间得到的加密结果不同,所以我们不能用常用的方法去验证密码是否正确(将密码加密后与数据库中的密码相比较)。YII2有自己的加密以及密码验证流程。 加密 $hash = Yii::$app->getSecurity()->genera... 阅读全文
posted @ 2015-09-29 23:42 慕尘 阅读(1544) 评论(0) 推荐(0) 编辑
摘要: User::find()->all(); 此方法返回所有数据;User::findOne($id); 此方法返回 主键 id=1 的一条数据(举个例子); User::find()->where(['name' => '小伙儿'])->one(); 此方法返回 ['name' => ... 阅读全文
posted @ 2015-09-28 10:46 慕尘 阅读(1218) 评论(0) 推荐(0) 编辑
摘要: models中LoginForm.phppublic $verifyCode;public function rules(){ return [ …… ['verifyCode', 'captcha', 'on' => 'login'], //验证码... 阅读全文
posted @ 2015-09-25 09:55 慕尘 阅读(495) 评论(0) 推荐(0) 编辑
摘要: yii2利用自带UploadedFile上传图片public static function uploadFile($name) { $uploadedFile = UploadedFile::getInstanceByName($name); if... 阅读全文
posted @ 2015-09-24 13:39 慕尘 阅读(693) 评论(0) 推荐(0) 编辑
摘要: js中uploader = WebUploader.create({ // 自动上传。 auto : true, // swf文件路径 swf : 'webuploader/Uploader.swf', // 文件接收服务端。 ... 阅读全文
posted @ 2015-09-24 13:28 慕尘 阅读(803) 评论(0) 推荐(0) 编辑
摘要: public $layout = 'layout';//在类中定义一个变量,名为$layout的php文件 阅读全文
posted @ 2015-09-24 09:40 慕尘 阅读(500) 评论(0) 推荐(0) 编辑
摘要: 添加use yii\helpers\Url;view中的连接//post为你的当前控制器名,index为view模版 阅读全文
posted @ 2015-09-24 09:27 慕尘 阅读(864) 评论(0) 推荐(0) 编辑
摘要: yii2判断数据是否存在$exists = ModelName::find()->where([ 'column_name' => $value])->andWhere(['column_name' => $value])->exists(); 阅读全文
posted @ 2015-09-24 09:06 慕尘 阅读(309) 评论(0) 推荐(0) 编辑
摘要: 出现400错误是yii2.0的csrf防范策略导致在components里面添加request配置如下:'request' => [ // !!! insert a secret key in the following (if it is empty) - this is required ... 阅读全文
posted @ 2015-09-24 01:16 慕尘 阅读(504) 评论(0) 推荐(0) 编辑