Add new action to RESTful Web Service

Hi, I’m using the tools that comes with Yii2 to create a REST Service but I need more resources that the ones that come by default (list/insert/etc). I’m overriding the current ones and it is working this way:




class TestController extends ActiveController

{

    public $modelClass = 'app\models\Test';


    public function actions()

    {

        $actions = parent::actions();

        unset($actions['index']);

        return $actions;

    }


    public function actionIndex()

    {

        //code

    }

    

}



Could someone please tell me if I am doing the overwrite in the right way ? And how can I create new actions for the REST service?

Thank you

On my config file I have the url manager like this:




'urlManager' => [

            'enablePrettyUrl' => true,

            'enableStrictParsing' => true,

            'showScriptName' => false,

            'rules' => [

                [

                    'class' => 'yii\rest\UrlRule',

                    'controller' => ['test'],

                    'pluralize' => false,

                    'extraPatterns' => [

                        'GET custom' => 'test/custom',

                    ],

                ],

            ],

        ],



I’m using the extraPatterns to define the route to the new action that is defined on the controller:




class TestController extends ActiveController

{

    public $modelClass = 'app\models\Test';




    public function actions()

    {

        $actions = parent::actions();


        unset($actions['index']);

        return $actions;

    }


    public function actionIndex()

    {

        //code

    }


    public function actionCustom()

    {

        //code

    }


}



With this code, when I call the index action the application recognizes it and return the action that is defined on that controller. But when I call the custom action I always get a 404 error.

Is my routing well configured? There is a lot of documentation on the definitive guide for the RESTful services but not regarding this topic of creating different actions for the API

Solved the problem setting the enablePrettyUrl to false, now it recognizes the new actions of the REST controller.