yii2-advanced-app

Yii2 REST api bearer authentication

纵饮孤独 提交于 2019-12-04 22:01:57
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 .. main.php <?php $params = array_merge( require(__DIR__ . '/../../common/config/params.php'), require(__DIR

Force HTTPS on Yii2

这一生的挚爱 提交于 2019-12-04 17:22:13
Requirement How to forcibly redirect to https (redirect if user accessing http) on Yii2? I already tried web.config to force https, but it didn't work. scenario I am using Yii2 advanced app hosted on IIS 7.5. Its actually very easy in Yii2 as there is a predefined method for your check. Just three steps needed: 1. Extend the application class Extend the default yii web-application class and override the handleRequest -method. Use the existing Yii2-function to check if the connection is secure. class MyApplication extends \yii\web\Application { public function handleRequest($request) { //check

Searching in GridView column with relation in Yii2

空扰寡人 提交于 2019-12-04 17:00: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->city_id]); And it works fine. But I also want to show region in my grid, and my table Cities has a

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 add spinner/loader in yii2 php

孤街醉人 提交于 2019-12-04 11:45:52
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 date time $api_url = 'http://xx.xxx.xxx.xxx:7000/api/meters/GetByMsn/' . $msn . '/' .$date_time; // my

Yii2 - Getting unknown property: yii\\console\\Application::user

坚强是说给别人听的谎言 提交于 2019-12-04 06:49:20
I am trying to run a console controller from the terminal, but i am getting this errors every time Error: Getting unknown property: yii\console\Application::user here is the controller class TestController extends \yii\console\Controller { public function actionIndex() { echo 'this is console action'; } } and this is the concole config return [ 'id' => 'app-console', 'basePath' => dirname(__DIR__), 'bootstrap' => ['log'], 'controllerNamespace' => 'console\controllers', 'modules' => [], 'components' => [ 'log' => [ 'targets' => [ [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning

Why by every refreshing page, cache reload anew?

送分小仙女□ 提交于 2019-12-04 06:41:20
问题 I've programmed my website by Yii2. When I refresh my website it works like Ctl + F5 , and all the font awesome and all the cache of my site reload again. It look likes I open the page first time. Link of my website 回答1: Add, this in your config file. According to your need. $linkAssets Whether to use symbolic link to publish asset files. Defaults to false, meaning asset files are copied to $basePath. Using symbolic links has the benefit that the published assets will always be consistent

Exception 'could not find driver' while migration in yii2

不想你离开。 提交于 2019-12-04 02:57:54
问题 This my stack trace: Exception 'yii\db\Exception' with message 'could not find driver' in /opt/lampp/htdocs/advanced/vendor/yiisoft/yii2/db/Connection.php:534 #0 /opt/lampp/htdocs/advanced/vendor/yiisoft/yii2/db/Connection.php(836): yii\db\Connection->open() #1 /opt/lampp/htdocs/advanced/vendor/yiisoft/yii2/db/Connection.php(823): yii\db\Connection->getMasterPdo() #2 /opt/lampp/htdocs/advanced/vendor/yiisoft/yii2/db/Command.php(208): yii\db\Connection->getSlavePdo() #3 /opt/lampp/htdocs

What the idea behind environment folders in Yii2 and how to use it?

扶醉桌前 提交于 2019-12-04 01:35:26
I've read through Yii2 documentation several times. I also googled and I couldn't find anything useful yet. The problem is I do not understand the concept of the environment folders. Please let me explain: I can use branches in Git (for dev, staging and production) *-local.conf files are ignored by Git and they won't be pushed to staging or production in anyway Why I have to duplicate all my controllers, views and other files in environment/dev & environment/prod ? In what folders I actually have to make my development? What the deployment procedure for environment folders? Should I call init

yii2 navbar with dropdown

早过忘川 提交于 2019-12-03 16:21:11
问题 After some simple edit on the default navbar, I got the code for the menu below... It would be very ugly if I add more menus. <?php NavBar::begin([ 'brandLabel' => 'My Project', 'brandUrl' => Yii::$app->homeUrl, 'options' => [ 'class' => 'navbar-inverse navbar-fixed-top', ], ]); $menuItems = [ ['label' => 'Home', 'url' => ['/site/index']], ['label' => 'Contact', 'url' => ['/site/contact'],'visible'=>false], ]; if (Yii::$app->user->isGuest) { $menuItems[] = ['label' => 'Signup', 'url' => ['