Yii2 error: yii \ base \ UnknownMethodException: unknown method call: yii \ web \ UrlManager :: addRules ()

After updating composer's dependencies today (using the composer update command), my Yii2 application became broken - it throws an Unknown method - yii \ base \ UnknownMethodException: calling an unknown method: yii \ web \ UrlManager :: addRules ()

After checking the vendor / yiisoft / yii2 / web / UrlManager.php file, I found that there was no addRule method. And the whole UrlManager class 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": "*" }, 
+6
source share
6 answers

This explains why this happened:

I think this is again a composer dependency resolver doing unexpected things:

  • you need yiisoft/yii2 in your composer.json, but you do not have the plugin for the linker installed.
  • then the dependency converter does not find packages with the bower-asset provider, so it looks for other versions of yiisoft/yii2 that have no conflict
  • As a result, yii2 beta is installed for installation

The correct solution, as already mentioned, is to install composer-asset-plugin :

 php composer.phar global require "fxp/composer-asset-plugin:1.0.*@dev" 
+12
source

I think they changed the way some libraries are loaded through the composer.

To solve this problem:

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 on @githubjeka and @SonicGD

+13
source

It seems that the update went completely wrong, since the files are different from the files on github - several functions are missing.

What I needed to do to get rid of this error:

Copy the code from the repository to 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.

+1
source

As ricardgf says, read the following:

https://github.com/yiisoft/yii2/blob/master/docs/guide/start-installation.md

then do:

composer.phar global require "fxp/composer-asset-plugin:1.0.*@dev"

and

composer.phar update --prefer-source --no-interaction

+1
source

ok I solved the problem of installing yii2 as follows:

global composer requires "fxp / composer-asset-plugin: 1.0. * @dev"

composer create-project --prefer-dist --stability = dev yiisoft / yii2-app-basic basic

+1
source

Try updating your composer.json as follows:

 "require": { "yiisoft/yii2": "*" }, 

in the project directory, write this command -

 php composer.phar update 
-4
source

Source: https://habr.com/ru/post/975395/


All Articles