yii2-advanced-app

Yii2 REST api bearer authentication

纵饮孤独 提交于 2019-12-06 13:11:50
问题 I am using Yii2 framework as the backend and react js for the client side. I am trying to create REST api with HTTPBearer authentication but always get a 401 Unauthorized error . I have followed the Yii2 Rest api authentication with no success. I have also implemented findIdentityByAccessToken on user.php and access_token on my sql. My files:- Folder structure:- -api --config --main.php --main-local.php ... --modules --v1 --controllers --CheckinsController.php -backend -common -frontend ..

Searching in GridView column with relation in Yii2

旧城冷巷雨未停 提交于 2019-12-06 10:52:00
问题 I have a model with foreign key city_id that references table Cities (id) . In the GridView I show city title instead of id, and I know how to add searching for column with foreign key, i.e, in view: GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [ //some columns [ 'attribute' => 'city_id', 'value'=>'city.title ], ]); And in search model ( search() function) I add: $query->joinWith('city'); $query->andFilterWhere(['like', 'cities.title', $this-

How to add spinner/loader in yii2 php

你离开我真会死。 提交于 2019-12-06 07:16:45
问题 I want to add a spinner/loader in one of my forms. The scenario is simple: When I hit the create button then it will show a spinner/loader. On hitting the create button a call to a web-service is made so the spinner/loader will show from call start to call end. Below is my controller: $m = MetersInventoryStore::findOne($_REQUEST['selected_meters']); $msn = $m->meter_serial; // current selected meter serial number is saved $date_time = str_replace(' ', 'T', date('Y-m-d H:i:s')); // current

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

From Backend to Frontend Yii2 Advanced App

谁说胖子不能爱 提交于 2019-12-06 03:28:45
I'm trying to link some controllers from frontend to backend. After some hours I don't where could be the problem. Backend file: main.php 'urlManager' => [ 'enablePrettyUrl' => false, 'showScriptName' => false, 'baseUrl' => '/backend/web', ], 'urlManagerFrontEnd' => [ 'class' => 'yii\web\urlManager', 'baseUrl' => '/frontend/web', 'enablePrettyUrl' => false, 'showScriptName' => false, ] file: SiteController.php public function actionIndex() { // User's variable $user = \common\models\User::findIdentity(Yii::$app->user->id); if($user->role != self::USER_ADMIN){ return $this->redirect(Url::to(Yii

Yii2 custom validator not working as guide suggests

只愿长相守 提交于 2019-12-06 02:12:45
I've searched around here for some time today, but I'm unable to understand why my validators aren't working in my model. I have a Module with a model "Page" in my code below. I have 2 attributes that I need to use to validate the model. They are hero_link and hero_linked. If hero_linked is true, I want to require hero_link. In the guide here , they explain the proper syntax for this kind of validator I have used this syntax in my model, but it doesn't validate as I'd expect. I've added the whenClient property as well, so I can use client side validation here. my relevant code is below: //

Yii2 best practices translating dynamic content

被刻印的时光 ゝ 提交于 2019-12-05 20:53:05
Can anyone share own experience and best practices implementing multilingual sites with Yii2? I want translate user input that is stored in database. For example article, that may have its name in three different languages, body and some translatable attributes as well. Does Yii2 have built in features to translate the dynamic content? Or should I use third party extensions like these ones below: https://github.com/creocoder/yii2-translateable https://github.com/LAV45/yii2-translated-behavior https://github.com/lajax/yii2-translate-manager Your help would be appreciated. Well, I can give you

Submitting Button Value to Controller but fail to post the value

我只是一个虾纸丫 提交于 2019-12-05 05:54:59
I know i have made mistakes here but i have been searching for this for the whole day. I used yii2 framework and i am still new here, I want to access partone/two page, the partone/two page has two submit buttons, one is for adding row, the second one is for validating the input inside PartoneController.php <? public function actionTwo() { if(\Yii::$app->user->isGuest) { $this->goHome(); } $models = []; $val = "" ; //Create array of items Yii::trace("Lets start: "); if(Yii::$app->request->post('addRow') == 'true'){ Yii::trace("hello"); Model::loadMultiple($models, Yii::$app->request->post(

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