Use backend url in REST API

Hello everybody,

In my common/config/main.php I have the following configuration

'urlBackend' => [

            'class' => 'yii\web\urlManager',

            'baseUrl' => '/backend/web/',

            'enablePrettyUrl' => false,

            'showScriptName' => true,


I have a model in the backend folder MessagesUsers, in this model I use Yii::$app->urlBackend->createUrl([‘user/view’,‘id’=>1]) which creates the correct url (localhost/backend/web/index.php?r=user/view&id=1 when it’s called from the corresponding backend controller.

In the api folder, I extend the MessagesUsers model, and when i call the corresponding api controller the Yii::$app->urlBackend->createUrl([‘user/view’,‘id’=>1]) generates the url(localhost/api/web/index.php?r=user/view&id=1) instead of localhost/backend/web/index.php?r=user/view&id=1)

What am I doing wrong?

Thank you.