`name` IS NULL 执行SQL查询并缓存结果 $styleId = Yii::$app->request->get('style'); $collection = Yii::$app->...获取url中的host信息: # http://localhost Yii::$app->request->getHostInfo() 获取url中的路径信息(不包含host和参数): Yii...r=news&id=1 Yii::$app->request->url 或者 Yii::$app->request->requestUri 获取完整url(含host以及参数): Yii::$app...Yii::$app->user->returnUrl; 获取Referer Yii::$app->request->headers['Referer'] 或者 Yii::$app->getRequest...GET 和 POST 过来的数据(得到结果是数组): // post Yii::$app->request->bodyParams // get Yii::$app->request->queryParams
\filters\auth\HttpBearerAuth 从认证服务器上获取基于OAuth2协议的access token,然后通过 HTTP Bearer Tokens 发送到API 服务器。...sign $sign = Yii::$app->request->get($this->signParam, null); $getParams = Yii::$app...->request->get(); $postParams = Yii::$app->request->post(); $params = array_merge($getParams...Yii::$app->request->isPost){ $error = ErrorCode::getError('params_error'); throw...Yii::$app->request->isPost){ $error = ErrorCode::getError('params_error'); throw
::$app->request->isPost) { $post = Yii::$app->request->post(); if ($model->add...() { $cateid = Yii::$app->request->get("cateid"); $model = ShopCategory::find()-...>where('cateid = :id', [':id' => $cateid])->one(); if (Yii::$app->request->isPost) {...$post = Yii::$app->request->post(); if ($model->load($post) && $model->save()) {...actionDel() { try { $cateid = Yii::$app->request->get('cateid');
获取执行的 SQL 语句 $query = User::find()->where(['LIKE', 'name', 'php%', false]); $commandQuery = clone $query...$id = Yii::$app->request->get('id'); $collection = Yii::$app->db->cache(function (Connection $db) use...); // 方法二 return (new SecondController('second', Yii::$app->module))->runAction('index', $data); 获取GET...数据 Yii::$app->getRequest->get('id'); // 效率更高 Yii::$app->getRequest()->get('id'); ---- 视图中获取当前模块/控制器/方法...id Yii::$app->controller->module->id; Yii::$app->controller->id Yii::$app->controller->action->id 防止
在 GridView 小部件是从数据提供者获取数据,并以一个表格的形式呈现数据。表中的每一行代表一个单独的数据项,列表示该项目的属性。...在 DataGrid 小部件中的列是在 yii\grid\Column 类中进行配置的。它代表一个模型属性,并可以进行过滤和排序。 GridView 列显示常用操作 app->request->get('type') == 1, ], // 设定宽度:如 title 列太长了,可以限定一下 [...->article_type_id, ]); // 时间搜索,用户在view上面输入的是字符串的时间,而数据库存放的是时间戳,需转换匹配 if ($this...php $searchModel = new ArticleSearch(); $dataProvider = $searchModel->search($_GET); return $this->render
() { if (Yii::$app->request->isPost) { $verifity = Yii::$app->request->post('...() { if (Yii::$app->request->isPost) { $verifity = Yii::$app->request->post('...->getSession(); $session->open(); //获取这个code 在session 中验证的总次数 $name = $this-...=Yii::$app->request->csrfToken ?...= \Yii::$app->request->csrfToken ?
:详情在cache.php中 // return $this->renderpartial('cache'); //一、数据缓存 //1、获取缓存组件...(['expression'=>'\YII::$app->request->get("name")']); //cache->add('key4','hello4',3000,...->renderPartial('index', $request=\YII::$app->request; echo $request->get...($session['user']); // echo $session->get('user'); //cookie // $cookie=\YII::$app...('1'); // $cookie->remove('id'); // $cookie=\YII::$app->request->cookies; /
Cookie 获取cookie $cookies = Yii::$app->request->cookies; 设置cookie $cookies = Yii::$app->response...GET/POST请求 Yii::$app->request->get(); Yii::$app->request->get("id"); Yii::$app->request->POST(); Yii...$app->request->isGet // 判断是否为GET请求 Yii::$app->request->isPost // 判断是否为POST请求 Yii::$app->request->isPjax...视图相关 渲染一个视图(如果布局有效则使用布局) $this->render('index',['model'=>$model]) 渲染视图(不使用布局) $this->renderPartial...主要解决DAO在查询语句上的繁琐问题,无需输入原生SQL语句就可以完成数据库检索。
->where(): 构建WHERE子句 ->join(): 在FROM子句中构建INNER JOIN 子句 ->leftJoin(): 在FROM子句中构建左连接子句...->rightJoin(): 在FROM子句中构建右连接子句 ->crossJoin(): 添加交叉查询片段(没用过) ->naturalJoin(): 添加一个自然连接子片段 ->group...()的一个例子: $post=Post::model()->find('postID=:postID', array(':postID'=>10)); // 如果查询条件很是复杂,就要使用CDbCriteria...->params=array(':postID'=>10); $post=Post::model()->find($criteria); // 不需要第二个参数 // 另一种更好的写法 $post=...Post::model()->find(array( 'select' => 'title', 'condition' => 'postID=:postID',
接入微信 Yii2后台配置 1.在app/config/params.php中配置token参数 return [ //微信接入 'wechat' =>[ 'token...GET["code"]; $state = $_GET["state"]; $appid = Yii::$app->params['wechat']['appid']; $appsecret...$userInfo = $this->getUserInfo($access_token,$openid); $user_check = WechatUser::find()->where(['...= Yii::$app->params['wechat']['key']; $notifyUrl = Yii::$app->params['wechat']['notifyUrl'];...wechat']['appid']; $mchid = Yii::$app->params['wechat']['mchid']; $key = Yii::$app->params['wechat
[get_called_class()]); } else { Yii::$app->loadedModules[get_class($instance)] = $instance...()获取App对象,类似于Yii::$app。...Object是基础类,所以绝大部分类都能直接调用配置文件中配置内容 如: var_dump(Yii::$app->name); 实际上config文件的数组中有name属性 return [...this->getRequest()); 摘出来的这句: $this->getRequest()//获取Request对象 这个没啥可说的,获取Request对象 $this->handleRequest...->getResponse(); /*这个是加载yii\base\Response类,在外部可以Yii::$app->get('response')、Yii::$app->getResponse()、
在网上搜了很多yii2图片上传插件,感觉这个和bootstrap融合的很好,比较能满足需求,故推荐给大家。 在使用过程中踩过不少坑,以下是具体使用说明。...$uploadNo = Yii::$app->request->post('upload_no', ''); //针对修改商品图片 $goodsId =...Yii::$app->request->post('goods_id', '0'); foreach ($this->imageFile as $file) {...::$app->request->isPost) { $uploadForm->imageFile = UploadedFile::getInstances($uploadForm...::$app->request->post('key')) { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON
过滤器本质上是一种特殊的行为。...为什么使用过滤器 通常情况下,过滤器将代码绑定到所有的操作上,也就是说,每一个操作的执行,都需要先或后执行过滤器,所以,可以用来执行权限检测、缓存处理等事情 在哪里使用过滤器 在控制器中,定义: public...Session使用.png Cookie的使用 //获取cookie的对象 $getCookieObj = Yii::$app->request->cookies; //设置cookie的对象 $setCookieObj...->get('tel')); //获取的是对象 var_dump($getCookieObj['tel']); 文件上传 在Yii里上传文件通常使用yii\web\UploadedFile类, 它把每个上传的文件封装成...) { //获取页码,参数需和Pagination中配置的参数一致 $page=Yii::$app->request->get("page");
若没有通过,你能通过 yii\base\Model::errors 属性获取相应的报错信息。...::$app->request->post()); // which is equivalent to the following: // $model->attributes = \Yii::$app...Status::find()->where(['id' => $value])->exists()) { $model->addError($attribute, $this->...This can be achieved by a code snippet like the following in the controller actions: if (Yii::$app->request...->isAjax && $model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON
中一次性级联查询,调用相关数据,都直接在查询出来的数据中直接获取 // 查询客户与他们的订单和国家 $customerList = CustomerModel::find()->with('orders...) { $query->andWhere('price_num>100'); }, ])->all(); 3.使用joinWith() // 在SQL中一次性级联查询,调用相关数据...,都直接在查询出来的数据中直接获取 // 查询客户与他们的订单和国家 $customerList = CustomerModel::find()->joinWith('orders')->all();...FROM order B) 再执行关联表SQL:SELECT * FROM user WHERE user_id IN (1,2,…) C) 再通过关联表SQL数据进行内存分配到各自的主表的每条数据上。...public function saveWithTrans() { $transaction = Yii::$app->db->beginTransaction(); $error =
->findModel(); $search_model = new TestSearch; $query = $model::find()->select(['*'])...用好yii\db\Query查询构建器包括关联表查询,尽量不要直接写sql语句。 控制器和视图中所用的字典类,获取数据的方法都应写到Model里。...: Yii::$app->request->getQueryParams(); $this->attributes = $params; $start_time = ArrayHelper...按照业务需求设置好字段的表单控件和验证规则 backend\modules\test\views\default_form.php 表单元素为必填项的在lable上的class加上form-required...status */ public static function Status($key = false){ $array = [ '0'=> '有效
GridView 两表联查/搜索/分页 当我们在一个网格视图中显示活动数据的时候,你可能会遇到这种情况,就是显示关联表的列的值,为了使关联列能够排序,你需要连接关系表,以及添加排序规则到数据提供者的排序组件中...empty($_GET['InfoSearch'])){ $getSearch = Yii::$app->request->get(); //接收搜索字段 $data = $searchModel->search...($getSearch); }else{ //小部件查询数据 $data = new ActiveDataProvider([ 'query' => BooksInfo::find(), //查询数据...scenarios() 函数 return Model::scenarios(); } public function search($params) { $query = BooksInfo::find...class' => 'yiigridActionColumn','header'=>'操作'], //动作列 ], 'pager' => [//自定义分页样式以及显示内容 'prevPageLabel'=>'上一页
access-token=xxxxxxxx, 由于大多数服务器都会保存请求参数到日志, 这种方式应主要用于JSONP 请求,因为它不能使用HTTP头来发送 access token OAuth 2 : 使用者从认证服务器上获取基于...*/ public function generateAccessToken() { $this->access_token=Yii::$app->security...*/ public function actionLogin() { $model = new LoginForm(); if ($model->load(Yii::$app->getRequest...; class ArticleController extends ActiveController { public $modelClass = 'api\models\User';...: $response = Yii::$app->response; $response->setStatusCode(422); return [ 'errmsg' => '用户名或密码错误!
相关环境 操作系统及IDE macOS 10.13.1 & PhpStorm2018.1.2 软件版本 PHP7.1.8 Yii2.0.14 在yii2中,管理加密解密的库叫做Security,它以yii2...组件的形式存在,因此你可以通过Yii::$app->security来获取并使用它。...if($code == Yii::$app->request->get('code')){ } 上面的比较逻辑,两个字符串是从第一位开始逐一进行比较的,发现不同就立即返回 false,那么通过计算返回的速度就知道了大概是哪一位开始不同的...而使用 compareString 比较两个字符串,无论字符串是否相等,函数的时间消耗是恒定的,这样可以有效的防止时序攻击。...接下来我们看一个例子代码 $token = Yii::$app->security->maskToken("123456"); echo Yii::$app->security->unmaskToken
::app()->request->redirect(Yii::app()->user->returnUrl);) 当强制显示登陆表单,比如判断用户是guest就一直列出登陆表单,不会调用loginRequired...])) $model->attributes=$_GET['Post']; $this->render('admin',array( 'model'=>$model, )); } 4、在view..., 'clickableImage' => true, 'imageOptions' => array('align'=>'top', 'title'=>'重新获取'), )); ?...复制代码 代码如下: Yii::app()->request->url; ctype_开始的几个函数,用于检查字任串是不是符合要求,代替了简单的正则表达式 CController中的setPageState...1 2 3 4 5 6 $app = Yii::createWebApplication($config); $app->onbeginRequest = 'begin'; $app->run();