Yii Framework Forum: call api from backend - header response content-type change - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

call api from backend - header response content-type change integration in Advanced template api call

#1 User is offline   trinkity 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 14-December 13

Posted 26 April 2017 - 03:19 AM

Hi,
My Yii2 application has advanced template.
App has 3 endpoints

rest
backend
frontend

And I wanted to call api methods from backend or frontend.

It work fine with this call in the backend controller
$response = Yii::$app->runAction('api/availability/create_availability');


But the problem is that when return create_availability, the content type of page change because i call internal api function and i can't render the page in the backend controller.
How can i call the api from backend without change header content-type ?
0

#2 User is offline   trinkity 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 14-December 13

Posted 26 April 2017 - 05:06 AM

Found the solution.

After runAction call
i set correct header in response

$response = Yii::$app->runAction('api/availability/create_availability');
Yii::$app->response->format = 'html';


so... every time i call internal api i must adjust the response format.
In this way i have a single point of failure :)

It works but this is correct way ?
0

#3 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,184
  • Joined: 17-January 09
  • Location:Russia

Posted 26 April 2017 - 06:06 AM

Yep. Wrap it into a method and use it.
Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I can work more on Yii: https://www.patreon.com/samdark
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users