Reputation: 1
I have created an rest calling framework in YII2. In this I have a class APIRequest From this class I want to render a page if I get an error from API.
My code:
public static function response($response,$serviceObject)
{
if($serviceObject->responseCode == 420)
{
$errorMessage = $response->errorMessage;
return \Yii::$app->getView()->renderFile('@app/views/merchants/error.php',['errorMessage'=>$errorMessage]);
}
else
{
return $response;
}
}
But this is not working.
Upvotes: 0
Views: 661
Reputation: 742
use
return \Yii::$app->view->renderFile('@app/views/merchants/error.php',['errorMessage'=>$errorMessage]);
instead of
return \Yii::$app->getView()->renderFile('@app/views/merchants/error.php',['errorMessage'=>$errorMessage])
Upvotes: 0
Reputation: 1236
Generally the Yii REST API doesn't use any views. See
http://www.yiiframework.com/doc-2.0/guide-rest-quick-start.html
Upvotes: 0
Reputation: 305
Not much information to go on. where is this method invoked? in the controller class?
perhapse this could help http://www.yiiframework.com/doc-2.0/guide-runtime-handling-errors.html
Upvotes: 1