Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override or edit code of vendor directory in yii2?

I need to do some changes in vendor/yiisoft/yii2/web/urlmanager.php for my url_alias to work! I need to know if I can change this file directly or is there any method to override this file?

like image 717
sphinx Avatar asked Jul 08 '16 16:07

sphinx


1 Answers

Best way is to create new URL Manager Class that extends existing UrlManager class i.e. yii/web/urlManager.php

i.e

class customUrlManager extends yii/web/urlManager {
.. code here
}

Then specify the class in your config element i.e frontend/config/main.php

 'urlManager' => [
            'class' => '<name_space>/customUrlManager'
            'enablePrettyUrl' => True,
            'showScriptName' => False,
            'rules' => [
                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
            ],
        ],
like image 181
Chetan Sharma Avatar answered Sep 23 '22 18:09

Chetan Sharma