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?
            Asked
            
        
        
            Active
            
        
            Viewed 1,326 times
        
    1 Answers
5
            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>',
            ],
        ],
 
    
    
        Chetan Sharma
        
- 2,539
- 5
- 25
- 41
