yii2-basic-app

Yii2 - How can I remove unnecessary information from log file?

一个人想着一个人 提交于 2019-12-08 03:13:39
问题 I am trying to log messages in Yii2 which are then emailed to my specified email address. config file web.php contains: 'mail' => [ 'class' => 'yii\log\EmailTarget', 'categories' => ['mail'], 'logVars' => [], 'mailer' => 'mailer', 'message' => [ 'from' => ['user@example.com'], 'to' => ['user1@example.com'], 'subject' => 'Log message', ], ], I am logging message like this: Yii::info('Log message example','mail'); After successful execution, I am receiving mail like this: 2018-07-31 09:01:12

In Yii2 framework, better place to define common function which is accessible everywhere like controller, model, view

牧云@^-^@ 提交于 2019-12-08 02:59:38
Like i want to create function with name "dt()" function dt(){ return date('Y-m-d H:i:s'); } and want to access it like this:- echo dt(); //retrun current date and time format Which is better place in Yii2 framework to do that? You can use it this way: http://www.yiiframework.com/extension/yii2-helpers/ Create a folder /common/helpers/ , then create a helper class there and add your static methods. namespace common\helpers; class DateHelper { public static function dt(){ return date('Y-m-d H:i:s'); } } Usage use common\helpers\DateHelper; echo DateHelper::dt(); For yii2, First Make a folder

How to upgrade Yii 1.x to Yii 2.0

ぐ巨炮叔叔 提交于 2019-12-06 23:23:59
问题 How to upgrade Yii 1.x version to Yii 2.0 latest release version? I am using ubuntu OS , Process to updating my old Yii to new Yii release version 2.0? 回答1: The Yii2 guide has excellent documentation in this regard see Upgrade from v1 I recently migrated couple of moderately complex applications from Yii 1.x to Yii 2.0. There are two ways to go about it , either you can run Yii 1.x and Yii 2 at the same time see using-yii-2-with-yii-1. Then migrate part by part, while it is possible it was

Error in accessing post json data in yii2

谁都会走 提交于 2019-12-06 06:45:00
问题 Am passing data to yii2 using ajax request but i keep on getting a 500 error This is the ajax request code: <?php $script = <<< JS $('form#forward_pr').on('beforeSubmit', function(e){ var keys = $('#grid').yiiGridView('getSelectedRows'); $.post({ url: "forwardpr", // your controller action dataType: 'json', data: {keylist: keys}, success: function(data) { alert('I did it! Processed checked rows.') }, error: function(err){ console.log("server error"); } }); return false; } ) ; JS; $this-

Yii2 - How to set dynamic authTimeout in User Identity?

折月煮酒 提交于 2019-12-06 03:40:49
Here, I have extended User Identity of Yii2. This is my configuration. 'user' => [ 'identityClass' => app\models\UserMaster::class, 'enableAutoLogin' => false, 'loginUrl' => ['/auth/login'], 'authTimeout' => 86400 ], Here, I have defined authTimout statically. But, What I want to do is that I want to fetch timeout value from database and set it in authTimeout . Thanks. You can use event to set authTimeout before request will be handled: 'as beforeRequest' => [ 'class' => function (Event $event) { /* @var $app \yii\web\Application */ $app = $event->sender; $app->getUser()->authTimeout = (new

How to login using two different model or switch identity class in yii2?

亡梦爱人 提交于 2019-12-06 02:36:58
问题 I want to allow user login from two different model. Config.php 'user' => [ 'identityClass' => 'app\models\User', //one more class here 'enableAutoLogin' => false, 'authTimeout' => 3600*2, ], LoginForm.php public function rules() { return [ // username and password are both required [['username', 'password'], 'required'], // rememberMe must be a boolean value ['rememberMe', 'boolean'], // password is validated by validatePassword() ['password', 'validatePassword'], ]; } public function

How to upgrade Yii 1.x to Yii 2.0

元气小坏坏 提交于 2019-12-05 03:26:48
How to upgrade Yii 1.x version to Yii 2.0 latest release version? I am using ubuntu OS , Process to updating my old Yii to new Yii release version 2.0? The Yii2 guide has excellent documentation in this regard see Upgrade from v1 I recently migrated couple of moderately complex applications from Yii 1.x to Yii 2.0. There are two ways to go about it , either you can run Yii 1.x and Yii 2 at the same time see using-yii-2-with-yii-1 . Then migrate part by part, while it is possible it was quite bit of pain, like trying to rebuild the second floor while living on the third. Alternatively you can

Error in accessing post json data in yii2

ぃ、小莉子 提交于 2019-12-04 14:21:35
Am passing data to yii2 using ajax request but i keep on getting a 500 error This is the ajax request code: <?php $script = <<< JS $('form#forward_pr').on('beforeSubmit', function(e){ var keys = $('#grid').yiiGridView('getSelectedRows'); $.post({ url: "forwardpr", // your controller action dataType: 'json', data: {keylist: keys}, success: function(data) { alert('I did it! Processed checked rows.') }, error: function(err){ console.log("server error"); } }); return false; } ) ; JS; $this->registerJS($script); ?> When i do console.log(keys) this returns [0, 1] This is my controller code: if (Yii:

How to login using two different model or switch identity class in yii2?

蹲街弑〆低调 提交于 2019-12-04 07:34:59
I want to allow user login from two different model. Config.php 'user' => [ 'identityClass' => 'app\models\User', //one more class here 'enableAutoLogin' => false, 'authTimeout' => 3600*2, ], LoginForm.php public function rules() { return [ // username and password are both required [['username', 'password'], 'required'], // rememberMe must be a boolean value ['rememberMe', 'boolean'], // password is validated by validatePassword() ['password', 'validatePassword'], ]; } public function validatePassword($attribute, $params) { if (!$this->hasErrors()) { $user = $this->getUser(); if (!$user || !

Twitter API : Not Getting User Email - Yii2

此生再无相见时 提交于 2019-12-02 05:46:24
I'm getting error like Unknown Property – yii\base\UnknownPropertyException Setting unknown property : yii\authclient\clients\Twitter::requestEmail Whenever I am including 'requestEmail' => 'true', in 'authClientCollection' => [ for components in web.php web.php $config = [ . . 'components' => [ . . 'authClientCollection' => [ 'class' => 'yii\authclient\Collection', 'clients' => [ 'twitter' => [ 'class' => 'yii\authclient\clients\Twitter', 'requestEmail' => 'true', 'consumerKey' => 'IFK2OMG0rKIFK2Jt4rLvw', 'consumerSecret' => 'ImTprQzaOMG0rKZsZiPDIvwIFK2aOMG0rKZsZiPD', ], ], ], ],