intheweb
intheweb

Reputation: 529

Yii2 Error: yii\base\UnknownMethodException: Calling unknown method: yii\web\UrlManager::addRules()

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": "*"
},

Upvotes: 6

Views: 13475

Answers (6)

iltaf khalid
iltaf khalid

Reputation: 10318

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

Upvotes: 1

ricardgf
ricardgf

Reputation: 458

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

Upvotes: 13

cebe
cebe

Reputation: 3819

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 of yiisoft/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"

Upvotes: 12

TomaszKane
TomaszKane

Reputation: 815

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

Upvotes: 1

Andreas Hinderberger
Andreas Hinderberger

Reputation: 1525

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.

Upvotes: 1

sprytechies
sprytechies

Reputation: 317

Try to update your composer.json into following way:

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

in project directory, write this command-

php composer.phar update

Upvotes: -4

Related Questions