PHP code example of sheershoff / yii2-module-urlrules

1. Go to this page and download the library: Download sheershoff/yii2-module-urlrules library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sheershoff / yii2-module-urlrules example snippets


'components' => [
        // ...
        'moduleUrlRules' => [
            'class' => '\sheershoff\ModuleUrlRules\ModuleUrlRules',
            // allowed modules lists the modules that affect the url rules
            'allowedModules' => ['v1'],
        ],
        // ...

return [
    'modules' => [
        'v1' => [
            'basePath' => '@api/modules/v1',
            'class' => 'api\modules\v1\Module'
        ]
    ],
    'components' => [
        // ...
        // this config is suitable for an API app
        'urlManager' => [
            'enablePrettyUrl' => true,
            'enableStrictParsing' => true,
            'showScriptName' => false,
            'rules' => [],
        ],
    ],
];


namespace api\modules\v1;
class Module extends \yii\base\Module
{
    public $controllerNamespace = 'api\modules\v1\controllers';

    public function getUrlRules()
    {
        return [
            [
                'class' => 'yii\rest\UrlRule',
                'controller' => [self::getUniqueId().'/city'],
            ],
        ];
    }
}