PHPackages                             sheershoff/yii2-module-urlrules - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. sheershoff/yii2-module-urlrules

ActiveYii2-extension[Framework](/categories/framework)

sheershoff/yii2-module-urlrules
===============================

Extension to support module url rules for Yii2.

1.0.2(9y ago)31.9k1[1 issues](https://github.com/sheershoff/yii2-module-urlrules/issues)MITPHPPHP &gt;=5.3.0

Since Sep 15Pushed 9y ago2 watchersCompare

[ Source](https://github.com/sheershoff/yii2-module-urlrules)[ Packagist](https://packagist.org/packages/sheershoff/yii2-module-urlrules)[ RSS](/packages/sheershoff-yii2-module-urlrules/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (4)Used By (0)

Yii2 Module Url Rules
=====================

[](#yii2-module-url-rules)

This extension allows declaring url rules for a module inside a module, making it easy to manage module url rules, e.g. for API modules.

This module is distributed under the MIT License (MIT).

Requirements
------------

[](#requirements)

Yii &gt;=2.0.0

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist sheershoff/yii2-module-urlrules

```

or add

```
"sheershoff/yii2-module-urlrules": "~1.0.0"
```

to the require section of your composer.json.

Configuration
-------------

[](#configuration)

To use this extension, you have to configure the components section in your application configuration and add getUrlRules or urlRules to your modules.

In your `main.php` for the desired app add the `moduleUrlRules` component:

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

Check that modules are declared and see the `urlManager` settings for your API app or at least enable the `enablePrettyUrl` option. E.g.:

```
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' => [],
        ],
    ],
];
```

In your `Module.php` for the module add the `getUrlRules` like the following:

```
