yii2

Yii 2.0 hiding /basic/web from the URL along with the index.php

怎甘沉沦 提交于 2019-12-19 04:05:13
问题 Plenty of information around the net on how to hide the index.php from your Yii 2.0 application URL, however, what I'm trying to do here is to also remove the '/basic/web/' from the URL. /basic/web is the directory from which the application is running and the configuration that I have so far is the following. That goes into the config file: 'urlManager' =>[ 'enablePrettyUrl' => true, 'showScriptName' => false, ], And this is my htaccess file that I have within the /web folder: RewriteEngine

yii2, google outh2 and scope

本小妞迷上赌 提交于 2019-12-19 02:15:32
问题 I am using Yii2, GoogleOAuth and yii2-user extension. I want to receive user google circles and set scope to my config: 'authClientCollection' => [ 'class' => 'yii\authclient\Collection', 'clients' => [ 'google' => [ 'class' => 'yii\authclient\clients\GoogleOAuth', 'clientId' => '758709912345-p4qp4lqihit5un1u6qb75msqp5m5j6d8.apps.googleusercontent.com', 'clientSecret' => 'ZygOIi1-0asfktUQ1pKOFOo', 'scope' => 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo

Yii2 model::find() with default where conditions

萝らか妹 提交于 2019-12-18 19:23:28
问题 Using Yii2 in the View... Products::find()->asArray()->all() returns all products as array. I'm looking for a way to make it return all products WHERE id != 1 I want to have only one place do modify what "->all()" returns for every model. I know that Product::find()->where('id != 1')->... is possible, but I don't want to write and maintain it in more than one place. 回答1: 1) You can simply override find() method in your model: /** * @return \yii\db\ActiveQuery */ public static function find()

Yii2 Override generic create Action in Rest ActiveController

我是研究僧i 提交于 2019-12-18 19:11:08
问题 I have a Rest API in Yii2, and Yii generates all actions view / update / create / delete I want to change the comportement of createMethode et garde the other methods, SO I can't use the class Controller, I should use the class ActiveController But I want that class do the same work, I need to add some action before creating and some actions after creating. So I need to override the actionCreate how can I do it ? 回答1: You can do the following class CountryController extends ActiveController {

How to count and group by in yii2

こ雲淡風輕ζ 提交于 2019-12-18 18:47:32
问题 I would like to generate following query using yii2: SELECT COUNT(*) AS cnt FROM lead WHERE approved = 1 GROUP BY promoter_location_id, lead_type_id I have tried: $leadsCount = Lead::find() ->where('approved = 1') ->groupBy(['promoter_location_id', 'lead_type_id']) ->count(); Which generates this query: SELECT COUNT(*) FROM (SELECT * FROM `lead` WHERE approved = 1 GROUP BY `promoter_location_id`, `lead_type_id`) `c` In yii 1.x I would've done the following: $criteria = new CDbCriteria();

Using Yii2 with array of data and a Gridview with sorting and filter

落爺英雄遲暮 提交于 2019-12-18 15:36:09
问题 I've an array $resultData = [ array("id"=>1,"name"=>"Cyrus","email"=>"risus@consequatdolorvitae.org"), array("id"=>2,"name"=>"Justin","email"=>"ac.facilisis.facilisis@at.ca"), array("id"=>3,"name"=>"Mason","email"=>"in.cursus.et@arcuacorci.ca"), array("id"=>4,"name"=>"Fulton","email"=>"a@faucibusorciluctus.edu"), array("id"=>5,"name"=>"Neville","email"=>"eleifend@consequatlectus.com"), array("id"=>6,"name"=>"Jasper","email"=>"lectus.justo@miAliquam.com"), array("id"=>7,"name"=>"Neville",

Using Yii2 with array of data and a Gridview with sorting and filter

一世执手 提交于 2019-12-18 15:36:08
问题 I've an array $resultData = [ array("id"=>1,"name"=>"Cyrus","email"=>"risus@consequatdolorvitae.org"), array("id"=>2,"name"=>"Justin","email"=>"ac.facilisis.facilisis@at.ca"), array("id"=>3,"name"=>"Mason","email"=>"in.cursus.et@arcuacorci.ca"), array("id"=>4,"name"=>"Fulton","email"=>"a@faucibusorciluctus.edu"), array("id"=>5,"name"=>"Neville","email"=>"eleifend@consequatlectus.com"), array("id"=>6,"name"=>"Jasper","email"=>"lectus.justo@miAliquam.com"), array("id"=>7,"name"=>"Neville",

Does PHP7's PDO ext read the entire result set into memory?

∥☆過路亽.° 提交于 2019-12-18 14:50:52
问题 I have noticed since I upgraded to PHP7 that some SQL statements no longer work and instead run out of memory. I have this code: $query = Yii::$app->db->createCommand('select * from tbl_title')->query(); while ($row = $reader->read()) { var_dump($row); exit(); } And Yii2's database abstraction is just an extremely thin layer over PDO's and does not do anything extra. query() does nothing extra except add a line to a log file (Yii2's) for profiling and reader->read() just calls the PDO stream

Upload Ajax file in yii2

寵の児 提交于 2019-12-18 13:39:17
问题 I want to upload file using Ajax in yii2 framework this is my code, but in controller "get Instance" return null because of serialize data; how can i do this? This is my controller: <?php public function actionUpdate($id) { $model = Signature::findOne([ 'user_id' => $id, ]); if ($model->load(Yii::$app->request->post())) { $model->file = UploadedFile::getInstance($model, 'file'); $model->file->saveAs('uploads/signature/' . $model->user_id . '.' . $model->file->extension); $model->url =

Yii2:-Pretty URL's are formed, but not working (says 404 “NOT FOUND”)

耗尽温柔 提交于 2019-12-18 12:35:54
问题 I have started learning yii2 and I tried to do pretty URL stuff, but failed. What I did:- in config/web.php (I have edited below): 'urlManager' => [ 'class' => 'yii\web\UrlManager', // Hide index.php 'showScriptName' => false, // Use pretty URLs 'enablePrettyUrl' => true, 'rules' => [ ], then I have created a .htaccess file and put it on root (it has below code): RewriteEngine on # if a directory or a file exists, use it directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST