Add route rules from Controller execute

Can i use function addRules() from urlManager in application controller class? Did exist some similar method to dynamic controll routes? (not from configs?).

As example i try to call addRules() next way’s:




namespace ...\...;


class ExampleController extends Controller {


    public function beforeAction($action)

    {

        Yii::$app->getUrlManager()->addRules([

            $this->id . '/<id:\w+>' => $this->id . '/read'

        ], true);

        return parent::beforeAction($action);

    }


}



and i’m also try to do this in __construct() function, but nothing change - rules still not workign.