yii2

Yii2 数据查询操作Query Builder集合

和自甴很熟 提交于 2019-12-30 16:29:21
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> YII2下对数据库进行查询操作的语句整理集合。 SELECT $query->select('dyn_id as id, dynasty.dyn_name')-> $query->select(['dyn_id as id', "CONCAT(dyn_name,'a')"])-> $query->select('user_id')->distinct()-> FORM $query->from('user'); $query->from(['public.user u', 'public.post p']); $query->from('public.user u, public.post p'); $query->from(['u' => 'public.user', 'p' => 'public.post']); ---------- $subQuery = (new Query())->select('id')->from('user')->where('status=1'); // SELECT * FROM (SELECT `id` FROM `user` WHERE status=1) u $query->from(['u' => $subQuery]); WHERE where('status=1

Yii 2.0 Restful Web Service Api

若如初见. 提交于 2019-12-30 07:43:09
问题 Anyone using the integrated RESTful Web Service in Yii 2.0(beta)? The instructions in the official documentation looks simple but it didn't work for me: I'm using the basic template, have used the gii module to create a simple 'category' model extending ActiveRecord , then i created the CategoriesController extending the ActiveController : # Content of the file app\controllers\CategoriesController.php <?php namespace app\controllers; use yii\rest\ActiveController; class CategoriesController

Yii2 Rest API Bearer Authentication

只谈情不闲聊 提交于 2019-12-30 06:13:09
问题 I've made a Yii2 REST API. With the API you can get a list of cars. Now I want to use the Bearer Authentication to protect the API. But I don't know how it works. First of all. I set up the authenticator in the behaviors method of my controller. public function behaviors(){ return [ 'contentNegotiator' => [ 'class' => ContentNegotiator::className(), 'formats' => [ 'application/json' => Response::FORMAT_JSON, ], ], 'authenticator' => [ 'class' => CompositeAuth::className(), 'authMethods' => [

Use limit range in yii2?

早过忘川 提交于 2019-12-30 06:09:11
问题 I want to get data from db using limit 12,20 . Here is my code: $Query = new Query; $Query->select(['um.id as USERid', 'um.first_name', 'um.last_name', 'um.email', 'COUNT(g.id) as guestCount']) ->from('user_master um') ->join('LEFT JOIN', 'guest g', 'g.user_id = um.id') ->limit(12,20) ->groupBy('um.id') ->orderBy(['um.id' => SORT_DESC]); $command = $Query->createCommand(); $evevtsUserDetail = $command->queryAll(); It is not working. It is giving me all rows. I also tried ->limit([12,20]) ,

How to get root directory in yii2

青春壹個敷衍的年華 提交于 2019-12-29 04:28:29
问题 yii2 Question My yii2 install in d:\wamp\www\yii2store I want to get above path to save images which will be uploaded by me or users. I have pass all available arguments in Yii::getAlias('@webroot') (below are the lists of argument which I have used). @yii - framework directory. @app - base path of currently running application. @runtime - runtime directory. @vendor - Composer vendor directory. @webroot - web root directory of currently running web application. @web - base URL of currently

Disable CSRF validation for individual actions in Yii2

£可爱£侵袭症+ 提交于 2019-12-27 17:30:50
问题 Is there a way to disable CSRF validation for some actions of the controller keeping it enabled for the other ones? In my case I have several configurable Action classes, that are intended to be injected into controllers. I can't pass csrf validation token into the AJAX request because the thing I'm working with is external (made not by me) WYSIWYG plugin at the frontend. Yes, I can still disable csrf validation of the whole controller using these actions, but it may be insecure. 回答1: For the

yii2项目实战之配置

女生的网名这么多〃 提交于 2019-12-27 15:04:45
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 作者:白狼 出处: http://www.manks.top/document/yii2-blog-config.html 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 yii2配置项的理解 说起项目的配置,一种简单的理解概念就是为项目做一个基本的配置,类似数据库配置、路由配置等等。但是yii2的配置往往更复杂一些,在yii2中,配置项一定是针对对象进行的配置,其作用就是对对象的初始化或者说是配置对象的默认属性。可能刚开始接触yii的会有一点不好理解,我们举个栗子进行说明: 假设我们需要为当前项目封装一个全局性的公共的方法,在yii2中怎么解决? 我们假设全局性的公共类文件位于common/components/Helper.php,其内容如下: <?php namespace common\components; class Helper { public function checkedMobile ($mobile) { return $mobile; } } 如果按照一般的方法调用,你只需要use一些这个类并调用我们的checkedMobile方法即可,但是,为了说明yii配置文件的使用规则,我们打开common\config

Mysql: get all distinct values from field serialized by PHP

时光毁灭记忆、已成空白 提交于 2019-12-25 23:07:31
问题 I have a movies table (has data from a legacy project) with the field genre which contains values serialized by PHP like: a:3:{i:0;s:9:"Animation";i:1;s:9:"Adventure";i:2;s:5:"Drama";} I'm working in a search page, & I need to find all unique genres of the current search result to be used as a filter in the page, as an example, if the search result was these 2 movies: The Dark Knight (action, crime, drama) Black Knight (fantasy, adventure, comedy) I want to know the combination of there

Error in wbranca dynagrid update

拥有回忆 提交于 2019-12-25 19:58:13
问题 Am using wbranca yii2 to create dynamic forms but the update action returns an error of array_combine(): Both parameters should have an equal number of elements This is the form for the update <div class="panel-body"> <?php DynamicFormWidget::begin([ 'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_] 'widgetBody' => '.container-items', // required: css class selector 'widgetItem' => '.item', // required: css class 'limit' => 10, // the

Yii2:how to get return value in view from model?

人走茶凉 提交于 2019-12-25 19:36:53
问题 I have a table name "staff".Staff table has one to many relation with attendance table. In model Staff.php public function getAttendances() { if(isset($_GET['startdat'])) $start_date=$_GET['startdat']; if(isset($_GET['enddate'])) $end_date=$_GET['enddate']; if(isset($_GET['startdat'])){ return $this->hasMany(Attendance::className(), ['staff_id' => 'id']) ->where('daytime >= "'.$start_date.'" and daytime<="'.$end_date.'"'); } else{ return $this->hasMany(Attendance::className(), ['staff_id' =>