Question

Following is my module config file

return array(
'controllers' => array(
    'invokables' => array(
        'RSMobile\Controller\User' => 'RSMobile\Controller\UserController',
    ),
),

// Routes for API calls
'router' => array(
    'routes' => array(

        'rsmobile' => array(
            'type' => 'segment',
            'options' => array(
                'route' => '/rsmobile',
                'defaults' => array(
                    'controller' => 'RSMobile\Controller\User',
                )
            ),

            // Child routes
            'child_routes' => array(
                // Route for "user" API
                'user' => array(
                    'type' => 'segment',
                    'options' => array(
                        'route' => '/user[/:id]',
                        'constraints' => array(
                                               'id'     => '[0-9a-zA-Z]+',
                                                              ),
                        'defaults' => array(
                            'controller' => 'RSMobile\Controller\User',
                        )
                    ),
                ),
          )

Question:

I have extends AbstractRestfulController in UserController file but, when i call this with www.example.com/rsmobile/user?userid=1 it call get-list instead of get.

Any Light on path would be helpful

Thanks

Was it helpful?

Solution

I think you want to use www.example.com/rsmobile/user?userid=1 pattern only and not www.example.com/rsmobile/user/1.

In AbstractRestfulController, $identifierName is set to id, by default. If it does not find id in list of params then it will call getList() method. So what you can do is in your controller(which must be extending AbstractRestfulController) write below code :

public function __construct() {
    $this->identifierName = 'userId'; // Override $identifierName value specified in AbstractRestfulController.
}

OTHER TIPS

What I understand is that the request is matching your /rsmobile/ route instead of /rsmobile/user route. is that it?

I don't know how you deal with the paramater userid but probably, you don't need it, and instead of www.example.com/rsmobile/user?userid=1 you can call www.example.com/rsmobile/user/1 that will match your route, and will give you an id parameter in your controller.

Also, I think you are missing the 'may_terminate' => true int the child route. Probably you should be:

        // Child routes
        'child_routes' => array(
            // Route for "user" API
            'user' => array(
                'type' => 'segment',
                 'may_terminate' => true,
                'options' => array(
                    'route' => '/user[/:id]',
                    'constraints' => array(
                                           'id'     => '[0-9a-zA-Z]+',
                                                          ),
                    'defaults' => array(
                        'controller' => 'RSMobile\Controller\User',
                    )
                ),
            ),
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top