How to set a default action for SocialEngine module

42 Views Asked by At

I have created a module with two controllers: Index and Pay. There are actions for both controllers, i.e.
Index -> indexAction
Pay -> indexAction, callbackAction, etc.
I have defined routes in the module's manifest.php, although it seems defining the routes in that file makes no difference as those routes work correctly anyway. The problem is when I browse the root of the module i.e. http://example.com/pgateway, only a specific action from my second controller (PayController->callbackAction) is executed. Why is that and how can I make say IndexController->indexAction the default page when example.com/pgateway is browsed?

My route definitions (manifest.php):

'routes' => [
    'pay_general' => [
        'route' => 'pgateway/:controller/:action/*',
        'defaults' => [
            'module' => 'pgateway',
            'controller' => 'pay',
            'action' => 'index',
        ],
        'reqs' => [
            'controller' => '\D+',
            'action' => '\D+',
        ],
    ],
    'pay_callback' => [
        'route' => 'pgateway/:controller/:action/*',
        'defaults' => [
            'module' => 'pgateway',
            'controller' => 'pay',
            'action' => 'callback',
        ],
        'reqs' => [
            'controller' => '\D+',
            'action' => '\D+',
        ],
    ],
],
1

There are 1 best solutions below

2
Ajit T Stephen On

route should be unique, in each definition. :action means it would work with values as well as empty. Incase of empty it will use defaults. In your case latest route is overriding.

Try removing pay_callback, it would work as in pay_general.

Convention is manage one route for a controller, and manage accordingly.