R
R
romany42016-08-14 14:44:27
Yii
romany4, 2016-08-14 14:44:27

How to correctly call a controller method from another template?

There is yii2 advanced template.
With the following template
-api
-console
-frontend
-backend
The names speak for themselves.
Let's say that I want to call the api controller method from fronted-a.
Now I do it through curl

$jsonContent = $сurl->post($IP . '/v1/user/auth', Yii::$app->getRequest()->post());

where the string "/v1/user/auth' is the path to the controller in the api-template (the controller itself is api\modules\v1\controllers\UserController, the actionAuth() method)
Let me explain that the api is being prepared for mobile clients, for the web client I want to avoid calling via
curl , but I need to avoid duplication, i.e. changes occur only in one place.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
romany4, 2016-08-16
@romany4

Late reply.
you just need to connect the module from another template to the required template (in the main.php config), then you can use the run method

D
Dmitry, 2016-08-14
@slo_nik

Good afternoon.
Maybe you've done something? Why a controller in api?
Maybe it would be more correct to simply create a class in the right directory, and connect it in the frontend via namespace and call the class method?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question