afterFind not executing when using custom action in RestFUL


I’m using RestFul Web Services (

I need to use my own custom “view” action and I’m unsetting view action in my controller:

public function actions()


        $actions = parent::actions();


        return $actions;


So then I can use my own view action:

	public function actionView($id)


             // my stuff


The problem is that afterFind method in my model is not executing, and "fields" (where I can define which fields to return depending on action) is not executing either.

How can I use these 2 overrides function in my model (afterFind and fields), but using a custom action for "view" in a RestFul Controller ?

Thank you

I found something, and I think this needs a FIX in Yii2 …

When you create a custom action to use with UrlRule, this action has to be named in LOWERCASE

So I was using "customIndex" as action name … and my method in controller was "actionCustomIndex"

This is NOT working because action name rules in Base/Controller.php (action’s methods, around lines 211 …)

It would be nice to have a fix for that, so I can name my custom action as I want with lower and upper cases.

maybe changing the rules from

preg_match(’/^[a-z0-9\\-_]+$/’, $id)


preg_match(’/^[A-Za-z0-9\\-_]+$/’, $id)

anyway, the problem about afterFind is still live … this function is not called with custom actions

Thank you