0

backend/controllers/AccessController.php

public function actionFault(){
$exception = Yii::$app->errorHandler->exception;

if ($exception !== null) {
    $statusCode = $exception->statusCode;
    $name = $exception->getName();
    $message = $exception->getMessage();

    $this->layout = 'layout';

    return $this->render('error', [
        'exception' => $exception,
        'statusCode' => $statusCode,
        'name' => $name,
        'message' => $message
    ]);
}

backend/config/main.php

 'components' => [
    // ...
    'errorHandler' => [
        'errorAction' => 'access/fault',
    ],
    // ...
],

If I am not wrong than actionError() will call when any error comes am i right ? But in my case actionError is not calling what i am doing wrong ?

Ramkishan Suthar
  • 353
  • 1
  • 6
  • 21
  • Is `AccessController` in `backend` app? Is `$exception` not `null`? – Bizley Oct 27 '16 at 07:26
  • yes AccessController is in backend and error function is not calling – Ramkishan Suthar Oct 27 '16 at 08:19
  • PHP Notice – yii\base\ErrorException Trying to get property of non-object – Ramkishan Suthar Oct 27 '16 at 08:20
  • this error is coming on my one page i think error function should call when this error come but it has not called. Am i right ? – Ramkishan Suthar Oct 27 '16 at 08:21
  • I would start by modifying my action according to the default [ErrorAction](https://github.com/yiisoft/yii2/blob/master/framework/web/ErrorAction.php) - maybe there is something missing. – Bizley Oct 27 '16 at 08:27
  • One more thing @BIzley. In one page there is 403 error comes that this error function is calling. Is anything i need to add for PHP error/warning/notice – Ramkishan Suthar Oct 27 '16 at 08:35
  • Default error displaying ini PHP settings should be fine. You can always change them like [here](http://stackoverflow.com/a/21429652/3364821). – Bizley Oct 27 '16 at 08:43
  • What should i do now / – Ramkishan Suthar Oct 27 '16 at 08:51
  • Give more info, like more details with this PHP Notice log. – Bizley Oct 27 '16 at 09:01
  • 2016-10-27 10:58:17 [127.0.0.1][36][sds54sa7363unnlebpecdl0][error][yii\base\ErrorException:8] exception 'yii\base\ErrorException' with message 'Trying to get property of non-object' in /opt/lampp/htdocs/project/backend/views/invoice/_form.php:105 – Ramkishan Suthar Oct 27 '16 at 09:10
  • Remove this `actionFault()` method, revert the `errorHandler` implementation to default `site/error` and add `ErrorAction` in the `actions()` method inside `SiteController` - if everything works then you can start working on your own implementation based on the default one. – Bizley Oct 27 '16 at 09:16
  • ok let me check – Ramkishan Suthar Oct 27 '16 at 09:17
  • Sadly it is still not working @Bizley :( – Ramkishan Suthar Oct 27 '16 at 09:21
  • So you are telling me the default Yii 2 error handler implementation does not work? It looks like you have broken it somehow. – Bizley Oct 27 '16 at 09:25
  • I have 3 setup of YII 2 in my htdocs directory. It is not working on any setup. Is there anything which i am missing ? – Ramkishan Suthar Oct 27 '16 at 09:28
  • I can not tell you without looking at your code. Check the default implementation by comparing your setup with advanced project template. [Config](https://github.com/yiisoft/yii2-app-advanced/blob/master/frontend/config/main.php#L36) and [controller](https://github.com/yiisoft/yii2-app-advanced/blob/master/frontend/controllers/SiteController.php#L58) – Bizley Oct 27 '16 at 09:32
  • If i have http error llike 403 or 404 then it is working and error() function is calling ? Do you have idea what is the problem in other type of php error ? – Ramkishan Suthar Oct 27 '16 at 09:33
  • ok @Bizley thank you – Ramkishan Suthar Oct 27 '16 at 09:34

0 Answers0