Reputation: 479
I'm in need to configure all of my models and controllers except SiteControllers as modules. I've managed to get simple views working, but can't get around with other controller actions.
To elaborate what I'm talking about, routes should be as following:
example.com => app/site/index
example.com/page => app/modules/page/default/index
example.com/page/<slug> => app/modules/page/default/view/<slug>
example.com/submit/1 => app/modules/page/default/submit/1
The first three are working as they should, but what about the following? Current urlManager
is:
'urlManager' => [
'class' => 'yii\web\UrlManager',
'showScriptName' => false,
'enablePrettyUrl' => true,
'rules' => [
'<module:\w+>/<action:\w+>' => '<module>/default/<action>/view',
'<module:\w+>/<controller:\w+>' => '<module>/<controller>/index',
'<module:\w+>/<controller:\w+>/<action:\w+>' => '<module>/<controller>/<action>',
'<module:\w+>/<controller:\w+>/<action:\w+>/<id:\w+>' => '<module>/<controller>/<action>/view',
],
],
Thanks in advance!
Upvotes: 2
Views: 1312
Reputation: 133400
If your models, controllers and view are coded like a Yii2 module require you don't need special route config .. you simple should declare a proper entry in module section of your confi/main.php
eg .. i have create a module migr in a my personal vendor location and i setted the module in config/main.php this way
'modules' => [
........
'migr' => [ // dfenx module for migration via web without console command
'class' => 'vendor\myVendorName\migr\Module',
],
the routing is automatically assigned using eg:
myproject/backend/web/index.php/migr/my-action
for the url don't invoke direcly but use UrlHelpers
use yii\helpers\Url;
Url::to(['module/controller/action', 'id' => $id]);
in this way the url is generated properly respect the config in urlManager
Upvotes: 1