yii2

Yii2 Never Logout Idle Or Away User

半世苍凉 提交于 2021-01-29 07:18:05
问题 User's in Yii appear to be logged out automatically if they close their browser or are idle for about a day (maybe less, I'm not sure). Is it possible to not log them out ever (or at least for a long time for month or year). Not sure if the Session parameters or Cookie parameters need to change. I've tried changing the parameters. 'components' => [ 'session'=>[ 'class' => 'yii\web\Session', 'cookieParams' => ['httponly' => true, 'lifetime' => 3600 * 4* 365], 'timeout' => 3600*4 *365,

Yii 2 file input renders hidden file input tag

你离开我真会死。 提交于 2021-01-29 07:15:52
问题 I am using yii2 to build a simple application with a signup feature. Problem is when I render a file input tag using active forms, it render a file input field and a hidden field. The validator then picks the one which is hidden and always says that profile image is required though it saves it in my upload directory and also adds the path to the database but still returns with this error. Thanks for any help. Here is the code: View: <?php $form = ActiveForm::begin(['id' => 'form-signup' ,

Provide Authentication in a Yii2 Application using Reactjs frontend

落爺英雄遲暮 提交于 2021-01-29 06:36:49
问题 I am working with a Yii2 API and a reactjs fronted. I want to implement authentication in my api such that only authenticated users using the Bear authentication class can access my API functions. I have implemented my Before actions as follows : //Yii::$app->response->format = Response::FORMAT_JSON; /*directly include pagination info in the request body to simplify client development*/ public $serializer = [ 'class' => 'yii\rest\Serializer', 'collectionEnvelope' => 'items', ]; public static

How do I set the user status (online/offline) in a Yii-2 application

天大地大妈咪最大 提交于 2021-01-29 03:27:55
问题 For this I wrote a function in the Gii generated User model which sets the 'status' field of the corresponding user table as follows public function setStatus() { if (!\Yii::$app->user->isGuest) { $this->status = 1; } else { $this->status = 0; } } Now in my Controller : public function actionLogout() { $usr = new \frontend\models\User; $usr->setStatus(); Yii::$app->user->logout(); return $this->goHome(); } But Yii throws an error: Cannot redeclare frontend\models\User::tableName(); I tried to

How do I set the user status (online/offline) in a Yii-2 application

南楼画角 提交于 2021-01-29 03:23:12
问题 For this I wrote a function in the Gii generated User model which sets the 'status' field of the corresponding user table as follows public function setStatus() { if (!\Yii::$app->user->isGuest) { $this->status = 1; } else { $this->status = 0; } } Now in my Controller : public function actionLogout() { $usr = new \frontend\models\User; $usr->setStatus(); Yii::$app->user->logout(); return $this->goHome(); } But Yii throws an error: Cannot redeclare frontend\models\User::tableName(); I tried to

Many-to-many relation in yii2 activedataprovider

三世轮回 提交于 2021-01-28 05:01:07
问题 I have many-to-many relation with three tables: Category , Product , ProductCategory . Relation in Category : public function getProductCategories() { return $this->hasMany(ProductCategory::className(), ['category_id' => 'id']); } Relation in Product : public function getProductCategories() { return $this->hasMany(ProductCategory::ClassName(), ['product_id' => 'id']); } And in ProductCategory public function getProduct() { return $this->hasOne(Product::className(), ['id' => 'product_id']); }

Why does Chrome add two tabs at the end of my xlsx file and by doing so, is corrupting the files?

99封情书 提交于 2021-01-27 20:07:22
问题 I am developing an app with yii2 and I am using PhpSpreadsheet to generate (Excel) .xlsx files. When I download a generated .xlsx file with Chrome, I can not open it with Excel (2019), since Excel prompts that the file is corrupted, offers to repair it but fails. First i suspected something wrong with the generator or the download process, but I've tested the download with Firefox, Edge and Filezilla - everything works as expected. A comparison of the downloaded files in hex shows just one

Yii2 - Return Response during beforeAction

喜欢而已 提交于 2021-01-27 14:00:33
问题 I am building a test API. I have created a Controller Page which extends from yii\rest\Controller. Actions needs to send a response. To access actions in this controller, a service_id value needs to be posted. If present I need to evaluate if that service_id exists, if it is active and belongs to the user logged in. If validation fails, I need to send a response. I am trying to do it using beforeAction(), but the problem is that return data is used to validate if action should continue or not

What is the use of “defined('YII_DEBUG') or” in “defined('YII_DEBUG') or define('YII_DEBUG', false);”?

一个人想着一个人 提交于 2021-01-27 05:06:07
问题 In the defined('YII_DEBUG') or define('YII_DEBUG', false); line of code we are checking if debug has defined previously it will do nothing but if not it will set to false . I did not get this I mean what if we want to override previous value and why we cant simply do define('YII_DEBUG', false); why it necessary to check previous value if we don't want to use that? 回答1: I didnt do it but you are not clear about my question, we can only change the YII_DEBUG value in /web/index.php. one more

What is the use of “defined('YII_DEBUG') or” in “defined('YII_DEBUG') or define('YII_DEBUG', false);”?

扶醉桌前 提交于 2021-01-27 05:04:39
问题 In the defined('YII_DEBUG') or define('YII_DEBUG', false); line of code we are checking if debug has defined previously it will do nothing but if not it will set to false . I did not get this I mean what if we want to override previous value and why we cant simply do define('YII_DEBUG', false); why it necessary to check previous value if we don't want to use that? 回答1: I didnt do it but you are not clear about my question, we can only change the YII_DEBUG value in /web/index.php. one more