public function beforeAction($action)
{
return parent::beforeAction($action);
}
public function runAction($id, $params = [])
{
try {
return parent::runAction($id, $params);
} catch (MyException $myException) {
//此处返回业务错误 比如返回json字符串错误
$result = [
'status' => $myException->getCode(),
'message' => $myException->getMessage(),
'data' => null
];
return json_encode($result, true);
} catch (\Exception $ex) {
throw $ex;
}
}
public function afterAction($action, $result)
{
return parent::afterAction($action, $result);
}
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/12/8 0008
* Time: 14:38
*/
namespace app\librarys;
class MyException extends \Exception
{
}
throw new MyException('错误信息');