yii2

What is best way to redirect on login page in yii2

左心房为你撑大大i 提交于 2020-01-13 03:55:09
问题 If user is not logged in then user should have to be redirect on login page, for that i found function which is working fine for me, i used below function public function beforeAction($action) { if (\Yii::$app->getUser()->isGuest && \Yii::$app->getRequest()->url !== Url::to(\Yii::$app->getUser()->loginUrl) ) { \Yii::$app->getResponse()->redirect(\Yii::$app->getUser()->loginUrl); } return parent::beforeAction($action); } This is working fine for me, but for this i need to add function in every

Auto login using “remember me” not working

橙三吉。 提交于 2020-01-11 11:48:13
问题 I am new to Yii2. I'm using Yii 2 basic template. I have the "remember me" functionality implemented on my web application, but it is not working as I think it was supposed to. I can successfully log in (with a checked "remember me" checkbox). But after closing the browser and opening the website again I am not logged in, but instead redirected to the login page. I have set enableAutoLogin to true in the config file 'user' => [ 'identityClass' => 'app\models\User', 'enableAutoLogin' => true,

Yii2: auto fill fields based on another field from related table

瘦欲@ 提交于 2020-01-11 06:06:48
问题 I have a MySQL table and model patient_entry which contains fields patient_name , city and state . I also have another table/model health_card which also contains patient_name , city and state . Suppose the patient_entry table is already filled with patient_name , city and state . When I am entering data in health_card form, when I select the patient_name via drop-down field related to patient_entry table, I want the related city and state fields to be auto-filled. My _form.php for health

Filter setup for related model in GridView

流过昼夜 提交于 2020-01-10 20:10:54
问题 I am trying to setup the filter for related model in Yii2's GridView widget, but I am keep getting the error like the filter value must be an integer. I have followed this question. Now, I have a two models Services.php and ServiceCharge.php . In ServiceCharge.php the relation is setup like: public function getServiceName() { return $this->hasOne(Services::className(),['id'=>'service_name']); } In the ServiceChargeSearch.php the code is like this: <?php namespace app\models; use Yii; use yii

Filter setup for related model in GridView

一曲冷凌霜 提交于 2020-01-10 20:09:50
问题 I am trying to setup the filter for related model in Yii2's GridView widget, but I am keep getting the error like the filter value must be an integer. I have followed this question. Now, I have a two models Services.php and ServiceCharge.php . In ServiceCharge.php the relation is setup like: public function getServiceName() { return $this->hasOne(Services::className(),['id'=>'service_name']); } In the ServiceChargeSearch.php the code is like this: <?php namespace app\models; use Yii; use yii

Yii2 | requires bower-asset/jquery

岁酱吖の 提交于 2020-01-10 10:07:12
问题 I'm trying to install Yii2 via composer: composer global require "fxp/composer-asset-plugin:~1.1.1" composer create-project --prefer-dist yiisoft/yii2-app-basic basic ~/.composer/composer.json { "require": { "fxp/composer-asset-plugin": "~1.1.1" } } result: Problem 1 - yiisoft/yii2 2.0.x-dev requires bower-asset/jquery 2.1.*@stable | 1.11.*@stable -> no matching package found. - yiisoft/yii2 dev-master requires bower-asset/jquery 2.1.*@stable | 1.11.*@stable -> no matching package found. -

Yii2 | requires bower-asset/jquery

倾然丶 夕夏残阳落幕 提交于 2020-01-10 10:07:09
问题 I'm trying to install Yii2 via composer: composer global require "fxp/composer-asset-plugin:~1.1.1" composer create-project --prefer-dist yiisoft/yii2-app-basic basic ~/.composer/composer.json { "require": { "fxp/composer-asset-plugin": "~1.1.1" } } result: Problem 1 - yiisoft/yii2 2.0.x-dev requires bower-asset/jquery 2.1.*@stable | 1.11.*@stable -> no matching package found. - yiisoft/yii2 dev-master requires bower-asset/jquery 2.1.*@stable | 1.11.*@stable -> no matching package found. -

How to implement Yii2 Modal Dialog on Gridview view and update button?

为君一笑 提交于 2020-01-09 03:50:48
问题 I would like to implement Yii2 modal dialog box on my gridview when view or update button is clicked at each row. Can anyone kindly advise on how to implement it? With advice from arogachev: This is an update on my codes <?php //var_dump($dataProvider); $gridColumns = [ [ 'format' => 'html', 'attribute' => 'avatar', 'label'=>'Image', 'headerOptions' => ['width' => '80%',], ], [ 'class' => 'yii\grid\ActionColumn', 'template' => '{view} {delete}', 'headerOptions' => ['width' => '20%', 'class' =

Yii2: validation errors that are not attribute specific

可紊 提交于 2020-01-07 08:28:12
问题 How do I handle generic validation errors in a Yii2 ActiveRecord model that do not relate to a specific attribute ? For example I need to completely prohibit saving a model when a related record/modal has been set to inactive. I can of course just pick a more or less random attribute and assign the error message to it, but what if the front end form doesn't have that attribute and therefore doesn't show the error? Or even worse, if a scenario later disables validation of that attribute (by

Why i getting an error “Call to a member function formName() on a non-object”

安稳与你 提交于 2020-01-07 03:15:13
问题 i try to save multilanguaged content My About model ... public function rules() { return [ [['status', 'date_update', 'date_create'], 'integer'], [['date_update', 'date_create'], 'required'], ]; } ... public function getContent($lang_id = null) { $lang_id = ($lang_id === null) ? Lang::getCurrent()->id : $lang_id; return $this->hasOne(AboutLang::className(), ['post_id' => 'id'])->where('lang_id = :lang_id', [':lang_id' => $lang_id]); } My AboutLang model public function rules() { return [ [[