I am trying to run yii but unable to this. I am getting following error:
commond : php yii
Exception 'yii\base\UnknownPropertyException' with message 'Setting unknown property: yii\console\Request::parsers'
in /var/www/html/alpha/html/vendor/yiisoft/yii2/base/Component.php:201
Stack trace:
#0 /var/www/html/alpha/html/vendor/yiisoft/yii2/BaseYii.php(529): yii\base\Component->__set('parsers', Array)
#1 /var/www/html/alpha/html/vendor/yiisoft/yii2/base/Object.php(105): yii\BaseYii::configure(Object(yii\console\Request), Array)
#2 [internal function]: yii\base\Object->__construct(Array)
#3 /var/www/html/alpha/html/vendor/yiisoft/yii2/di/Container.php(381): ReflectionClass->newInstanceArgs(Array)
#4 /var/www/html/alpha/html/vendor/yiisoft/yii2/di/Container.php(156): yii\di\Container->build('yii\\console\\Req...', Array, Array)
#5 /var/www/html/alpha/html/vendor/yiisoft/yii2/BaseYii.php(348): yii\di\Container->get('yii\\console\\Req...', Array, Array)
#6 /var/www/html/alpha/html/vendor/yiisoft/yii2/di/ServiceLocator.php(135): yii\BaseYii::createObject(Array)
#7 /var/www/html/alpha/html/vendor/yiisoft/yii2/console/Application.php(219): yii\di\ServiceLocator->get('request')
#8 /var/www/html/alpha/html/vendor/yiisoft/yii2/base/Application.php(380): yii\console\Application->getRequest()
#9 /var/www/html/alpha/html/yii(31): yii\base\Application->run()
#10 {main}
parsers property is available in yii\web\Request, not in yii\console\Request.
Probably you have got your console configuration merged with web configuration where this property is set. If so, make sure console configuration is set with separate request component setup. If this is not the case of configs merge remove this property in console configuration.
It`s work for my issue:
Edit file : console/config/main.php
'components' => [
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'request' => [
'parsers' => new \yii\helpers\UnsetArrayValue(), //Add this line
],
],
Related
My Yii2 app is emailing me these errors.
2021-08-15 21:23:54
[192.228.155.xxx][-][a217lked49000ii06qtrivbrnl][error][yii\web\HttpException:400]
yii\web\BadRequestHttpException: Unable to verify your data
submission. in
/var/www/html/vendor/yiisoft/yii2/web/Controller.php:218
Stack trace:
#0 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(179):
yii\web\Controller->beforeAction()
#1 /var/www/html/vendor/yiisoft/yii2/base/Module.php(534):
yii\base\Controller->runAction()
#2 /var/www/html/vendor/yiisoft/yii2/web/Application.php(104):
yii\base\Module->runAction()
#3 /var/www/html/vendor/yiisoft/yii2/base/Application.php(392):
yii\web\Application->handleRequest()
#4 /var/www/html/frontend/web/index.php(64):
yii\base\Application->run()
#5 {main}
2021-08-15 21:23:54
[192.228.155.xxx][-][a217lked49000ii06qtrivbrnl][info][application]
$_POST = [
'_csrf'=>
'pejM1w_BV9Xj_HRgo9AsjsNW130aTEzqqx61C1PXFyLuvfWvX7d6oLKMJgzanWfenDi8KSopC66ab9JqIadzDw=='
'calculatorForm' => [
'instype' => '1'
'txtSumInsuredMtr' => '10,001'
'CCMtr' => '201.3'
'txtBasicPremiumSub' => ''
'NCDMtr' => ''
'txtBasicPremiumTotalMotor' => ''
'rider' => '1'
'stampDutyMotor' => ''
]
'ajax' => 'calculatorForm'
]
I have no idea why. Line 64 in index.php is this
(new yii\web\Application($config))->run();
The post request in the log is a calculator form. it works fine when i test it. Any ideas?
I try to execute this code in controller
throw new ForbiddenHttpException();
I excpeted to see 403 error, but I see following error:
An Error occurred while handling another error:
yii\web\ForbiddenHttpException: You are not allowed to perform this action. in C:\xampp\htdocs\university\vendor\yiisoft\yii2\filters\AccessControl.php:158
Stack trace:
#0 C:\xampp\htdocs\university\vendor\yiisoft\yii2\filters\AccessControl.php(140): yii\filters\AccessControl->denyAccess(Object(yii\web\User))
#1 C:\xampp\htdocs\university\vendor\yiisoft\yii2\base\ActionFilter.php(77): yii\filters\AccessControl->beforeAction(Object(yii\web\ErrorAction))
#2 [internal function]: yii\base\ActionFilter->beforeFilter(Object(yii\base\ActionEvent))
#3 C:\xampp\htdocs\university\vendor\yiisoft\yii2\base\Component.php(627): call_user_func(Array, Object(yii\base\ActionEvent))
#4 C:\xampp\htdocs\university\vendor\yiisoft\yii2\base\Controller.php(276): yii\base\Component->trigger('beforeAction', Object(yii\base\ActionEvent))
#5 C:\xampp\htdocs\university\vendor\yiisoft\yii2\web\Controller.php(164): yii\base\Controller->beforeAction(Object(yii\web\ErrorAction))
#6 C:\xampp\htdocs\university\vendor\yiisoft\yii2\base\Controller.php(155): yii\web\Controller->beforeAction(Object(yii\web\ErrorAction))
#7 C:\xampp\htdocs\university\vendor\yiisoft\yii2\base\Module.php(528): yii\base\Controller->runAction('error', Array)
#8 C:\xampp\htdocs\university\vendor\yiisoft\yii2\web\ErrorHandler.php(108): yii\base\Module->runAction('site/error')
#9 C:\xampp\htdocs\university\vendor\yiisoft\yii2\base\ErrorHandler.php(111): yii\web\ErrorHandler->renderException(Object(yii\web\ForbiddenHttpException))
#10 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\web\ForbiddenHttpException))
#11 {main}
I think you forgot to add a rule for error action in access rules
you can use this code in behaviors:
[
'actions' => ['error'],
'allow' => true,
'roles' => ["?","#"],
],
or in access rules use only for actions you need permission
I have been fighting with this problem for hours and cannot get through. I want to run API tests with Yii2 and (of course) Codeception. Here is my api.suite.yml
class_name: ApiTester
modules:
enabled:
- REST:
url: /mobile
depends: Yii2
part: Json
- \Helper\Api
config:
Yii2:
entryUrl: http://localhost:8080/index-test.php
and my test file UserLoginCept.php
<?php
$I = new ApiTester($scenario);
$I->wantTo('Test User Login');
$I->sendPOST('mobile/login', ['username' => 'uname', 'password' => '123456']);
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
$I->seeResponseContainsJson(['success'=>true]);
Results are logged below. The problem is the Test is calling site/index which is in the root project not mobile module. I can sense that it is picking wrong URL somewhere as I cannot see any trace of the module being called. If I try URL on Browser it works fine
http://localhost:8080/index.php/mobile/api/login
{
"success": false,
"token": ""
}
can someone help me spot what am doing wrong? I have read as much as I could could not find the issue.
Codeception Results
$~ codecept --debug run api
Codeception PHP Testing Framework v2.2.10
Powered by PHPUnit 4.8.35 by Sebastian Bergmann and contributors.
Rebuilding ApiTester...
Api Tests (1) -----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Modules: REST, Yii2, \Helper\Api
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
UserLoginCept: Test User Login
Signature: UserLoginCept
Test: tests/api/UserLoginCept.php
Scenario --
I send post "/mobile/api/login",{"username":"uname","password":"123456"}
[Request] POST /mobile/mobile/api/login {"username":"uname","password":"123456"}
[Request Headers] []
[yii\db\Connection::open] 'Opening DB connection: mysql:host=localhost;dbname=database_name'
ERROR
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1) UserLoginCept: Test user login
Test tests/api/UserLoginCept.php
[Error] Call to a member function isAdmin() on null
Scenario Steps:
1. $I->sendPOST("/mobile/api/login",{"username":"uname","password":"123456"}) at tests/api/UserLoginCept.php:4
#1 /Users/hosanna/Projects/Volcano/WebApp/vendor/yiisoft/yii2/base/View.php:328
#2 /Users/hosanna/Projects/Volcano/WebApp/vendor/yiisoft/yii2/base/View.php:250
#3 /Users/hosanna/Projects/Volcano/WebApp/vendor/yiisoft/yii2/base/Controller.php:396
#4 /Users/hosanna/Projects/Volcano/WebApp/vendor/yiisoft/yii2/base/Controller.php:382
#5 /Users/hosanna/Projects/Volcano/WebApp/controllers/SiteController.php:74
#6 app\controllers\SiteController->actionIndex
#7 /Users/hosanna/Projects/Volcano/WebApp/vendor/yiisoft/yii2/base/InlineAction.php:57
#8 /Users/hosanna/Projects/Volcano/WebApp/vendor/yiisoft/yii2/base/Controller.php:156
#9 /Users/hosanna/Projects/Volcano/WebApp/vendor/yiisoft/yii2/base/Module.php:523
#10 /Users/hosanna/Projects/Volcano/WebApp/vendor/yiisoft/yii2/web/Application.php:102
<!DOCTYPE html>
<html lang="en-US">
..... rest of HTML.....
So here is how I solved it:
changed suite.api.yaml to use test-index.php
class_name: ApiTester
modules:
enabled:
- Yii2
- REST:
url: http://localhost:8080/index-test.php/mobile/
depends: Yii2
part: Json
configFile: 'config/test.php'
- \Helper\Api
config:
Yii2:
I then changed the config file referred by text-index (config/test.php) to include pretty URLs:
<?php
$params = require(__DIR__ . '/params.php');
$dbParams = require(__DIR__ . '/test_db.php');
/**
* Application configuration shared by all test types
*/
return [
'id' => 'basic-tests',
'basePath' => dirname(__DIR__),
'language' => 'en-US',
'modules' => [
'mobile' => [
'class' => 'app\modules\mobile\Module',
],
],
'components' => [
'db' => $dbParams,
'mailer' => [
'useFileTransport' => true,
],
'assetManager' => [
'basePath' => __DIR__ . '/../web/assets',
],
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => false,
'showScriptName' => true,
'rules' => [
['class' => 'yii\rest\UrlRule', 'controller' => 'mobile/api'],
],
],
'user' => [
'identityClass' => 'app\modules\mobile\models\User',
],
'request' => [
'cookieValidationKey' => 'test',
'enableCsrfValidation' => false,
// but if you absolutely need it set cookie domain to localhost
/*
'csrfCookie' => [
'domain' => 'localhost',
],
*/
],
],
'params' => $params,
];
After that tests were running fine!
I use following code:
'as beforeRequest' => [
'class' => 'yii\filters\AccessControl',
'rules' => [
[
'actions' => ['login', 'forgot', 'error'], // guests can just login and nothing else
'allow' => true,
'roles' => ['?'],
],
[
'allow' => true,
'roles' => ['admin', 'access'],
],
],
],
Using this code causes following errors (if a user is logged in, but have not the role admin or access):
An Error occurred while handling another error:
yii\web\ForbiddenHttpException: Sie dürfen diese Aktion nicht durchführen. in /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/filters/AccessControl.php:154
Stack trace:
0 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/filters/AccessControl.php(137): yii\filters\AccessControl->denyAccess(Object(yii\web\User))
1 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/base/ActionFilter.php(75): yii\filters\AccessControl->beforeAction(Object(yii\web\ErrorAction))
2 [internal function]: yii\base\ActionFilter->beforeFilter(Object(yii\base\ActionEvent))
3 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/base/Component.php(545): call_user_func(Array, Object(yii\base\ActionEvent))
4 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/base/Module.php(676): yii\base\Component->trigger('beforeAction', Object(yii\base\ActionEvent))
5 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/base/Controller.php(144): yii\base\Module->beforeAction(Object(yii\web\ErrorAction))
6 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/base/Module.php(523): yii\base\Controller->runAction('error', Array)
7 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/web/ErrorHandler.php(97): yii\base\Module->runAction('site/error')
8 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/base/ErrorHandler.php(111): yii\web\ErrorHandler->renderException(Object(yii\web\ForbiddenHttpException))
9 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\web\ForbiddenHttpException))
10 {main}
Previous exception:
yii\web\ForbiddenHttpException: Sie dürfen diese Aktion nicht durchführen. in /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/filters/AccessControl.php:154
Stack trace:
0 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/filters/AccessControl.php(137): yii\filters\AccessControl->denyAccess(Object(yii\web\User))
1 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/base/ActionFilter.php(75): yii\filters\AccessControl->beforeAction(Object(yii\base\InlineAction))
2 [internal function]: yii\base\ActionFilter->beforeFilter(Object(yii\base\ActionEvent))
3 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/base/Component.php(545): call_user_func(Array, Object(yii\base\ActionEvent))
4 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/base/Module.php(676): yii\base\Component->trigger('beforeAction', Object(yii\base\ActionEvent))
5 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/base/Controller.php(144): yii\base\Module->beforeAction(Object(yii\base\InlineAction))
6 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/base/Module.php(523): yii\base\Controller->runAction('', Array)
7 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/web/Application.php(102): yii\base\Module->runAction('', Array)
8 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/base/Application.php(380): yii\web\Application->handleRequest(Object(yii\web\Request))
9 /Applications/XAMPP/xamppfiles/htdocs/cms/backend/web/index.php(17): yii\base\Application->run()
10 {main}
If I use ['#'] instead of ['admin', 'access'] it works fine. That means that site/error is rendering probably.
But using ['admin, 'access'] causes errors (in text form) and site/error is NOT rendering probably. Why?
admin is a defined rule and access is a permission. Everything works great using in controllers.
Does anyone have an idea what's wrong here?
Thank you!
It seems that you have an error and the application try to show the error page. But the user don't have access to the error page too.
When I enter command yii or test/codeception/bin/yii migrate in the console, receive such a message
Fatal error: Uncaught exception 'yii\base\UnknownPropertyException' with message 'Setting unknown property: yii\console\ErrorHandler::errorAction' in D:\Desktop\loalhost\yii2-wiersz\vendor\yiisoft\yii2\base\Component.php:197
Stack trace:
#0 D:\Desktop\loalhost\yii2-wiersz\vendor\yiisoft\yii2\BaseYii.php(518): yii\base\Component->__set('errorAction', 'site/error')
#1 D:\Desktop\loalhost\yii2-wiersz\vendor\yiisoft\yii2\base\Object.php(105): yii\BaseYii::configure(Object(yii\console\ErrorHandler), Array)
#2 [internal function]: yii\base\Object->__construct(Array)
#3 D:\Desktop\loalhost\yii2-wiersz\vendor\yiisoft\yii2\di\Container.php(372): ReflectionClass->newInstanceArgs(Array)
#4 D:\Desktop\loalhost\yii2-wiersz\vendor\yiisoft\yii2\di\Container.php(151): yii\di\Container->build('yii\\console\\Err...', Array, Array)
#5 D:\Desktop\loalhost\yii2-wiersz\vendor\yiisoft\yii2\BaseYii.php(344): yii\di\Container->get('yii\\console\\Err...', Array, Array)
#6 D:\Desktop\loalhost\yii2-wiersz\vendor\yiisoft\yii2\di\ServiceLocator.php(13 in D:\Desktop\loalhost\yii2-wiersz\vendor\yiisoft\yii2\base\Component.php on line 197
console/config/main.php is default. Problem is on localhost (win7x62) and remote host (debian).
I had the same situation with the attempt to migrate rbac
(yii migrate --migrationPath=#yii/rbac/migrations)
What is causing the problem ??? my ignorance ;)?
Well, as you error message says, you are trying to set unknown property 'errorAction'. I suppose you are using the same error component config here in console app as in web app. See if there is
[
'components' => [
'error' => [
'errorAction' => ...
]
]
]
in your console app config. There shouldn't be 'errorAction'.
Thanks,
I moved from frontend/config and backend/config code
'errorHandler' => [
'errorAction' => 'site/error',
]
to common/config. Frontend and backend app did not have a problem with that, but console yes. After rollback is ok.