Yii2 Error: yii\base\UnknownMethodException: Calling unknown method: yii\web\UrlManager::addRules()
Solution 1
Here is an explaination of why this happened:
I think this is again the composer dependency resolver doing unexpected things:
- you require
yiisoft/yii2
in your composer.json but do not have the composer asset plugin installed.- then the dependency resolver does not find packages with vendor
bower-asset
so it looks for other versions ofyiisoft/yii2
that do not have conflict- The result is to install the beta version of yii2 to be installed
The correct solution as already mentioned is to install the composer-asset-plugin:
php composer.phar global require "fxp/composer-asset-plugin:1.0.*@dev"
Solution 2
I think they have changed the way some libraries are loaded through composer.
To solve it:
Add to composer.json
"extra": {
"asset-installer-paths": {
"npm-asset-library": "vendor/npm",
"bower-asset-library": "vendor/bower"
}
}
and run:
# php composer.phar global require "fxp/composer-asset-plugin:1.0.*@dev"
# php composer.phar update --dev
More info: Issue on Github and Issue on Github
Full credit to: @githubjeka and @SonicGD
Solution 3
It seems the update went totally wrong, since the files are different from the ones on github - several functions missing.
What i had to do to get "rid" of this error:
Copy the code from the repository in your local files:
https://github.com/yiisoft/yii2/blob/master/framework/web/UrlManager.php
https://raw.githubusercontent.com/yiisoft/yii2/master/framework/helpers/BaseHtml.php
This solved it for the moment for me.
Solution 4
Like ricardgf says, read this:
https://github.com/yiisoft/yii2/blob/master/docs/guide/start-installation.md
then run:
composer.phar global require "fxp/composer-asset-plugin:1.0.*@dev"
and
composer.phar update --prefer-source --no-interaction
Solution 5
ok I solved the problem installing yii2 in this way :
composer global require "fxp/composer-asset-plugin:1.0.*@dev"
composer create-project --prefer-dist --stability=dev yiisoft/yii2-app-basic basic
Andy Webov
Updated on June 18, 2022Comments
-
Andy Webov almost 2 years
After todays update of composer dependencies (with composer update command) my Yii2 application became broken - It throws Unknown Method – yii\base\UnknownMethodException: Calling unknown method: yii\web\UrlManager::addRules()
After inspecting vendor/yiisoft/yii2/web/UrlManager.php file I found that there is no method addRule. And the whole entire class UrlManager is different from the class in the repository.
My composer.json:
"minimum-stability": "dev", "require": { "php": ">=5.4.0", "yiisoft/yii2": "*", "yiisoft/yii2-bootstrap": "*", "yiisoft/yii2-swiftmailer": "*", "yiisoft/yii2-gii": "2.0.0-beta", "claudejanz/yii2-mygii": "*", "kartik-v/yii2-grid": "dev-master", "kartik-v/yii2-builder": "dev-master", "2amigos/yii2-switch-widget": "*", "yiisoft/yii2-jui": "*", "DsXack/yii2-underscore": "*", "2amigos/yii2-editable-widget": "*", "warrence/yii2-kartikgii": "*" }, "require-dev": { "yiisoft/yii2-codeception": "*", "yiisoft/yii2-debug": "*" },