Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't access to message property of HttpException. #2503

Closed
timfayz opened this issue Feb 20, 2014 · 7 comments
Closed

Can't access to message property of HttpException. #2503

timfayz opened this issue Feb 20, 2014 · 7 comments
Assignees
Labels

Comments

@timfayz
Copy link

timfayz commented Feb 20, 2014

Hello, I can't access to message property of exception's object. Is in normal?

My simple code:

  #SiteController.php
  #I changed errorHandler action to site/error in configurations.
  public function actionError()
  {
    $this->layout = 'container';
    if (\Yii::$app->exception !== null) {
      return $this->render('error', ['exception' => \Yii::$app->exception]);
    }
  }

  public function actionPage($view = 'index')
  {
    try {
      return $this->render('site/page/'.$view);
    } catch (InvalidParamException $e) {
      throw new HttpException(404, 'Страница не найдена');
    }
  }

When I go to nonexist page, I get the following:

yii\web\HttpException Object
(
    [statusCode] => 404
    [message:protected] => Страница не найдена #custom message naturally inaccessible

It means that I can't insert $exception->message into view file.

@cebe
Copy link
Member

cebe commented Feb 20, 2014

Yii Exception classes extend from PHP exception so they have the same properties and methods. message property is protected so you have to use getMessage() to retrieve it. http://www.php.net/manual/en/class.exception.php

@cebe cebe closed this as completed Feb 20, 2014
@timfayz
Copy link
Author

timfayz commented Feb 20, 2014

Thank you again!

Yii Exception classes extend from PHP exception

I don't have deep PHP knowledges..Is it so obviously?
Sorry for disturb, I write there because at http://stuff.cebe.cc/yii2docs/yii_base_exception.html I got nothing about it..

@samdark
Copy link
Member

samdark commented Feb 20, 2014

@cebe it seems we need to inspect PHP classes when generating methods.

@cebe cebe reopened this Feb 20, 2014
@cebe cebe added this to the 2.0 Beta milestone Feb 20, 2014
@cebe cebe self-assigned this Feb 20, 2014
@qiangxue
Copy link
Member

Also in method detail display, we should show whether the method is public or private.

cebe added a commit that referenced this issue Feb 20, 2014
@cebe
Copy link
Member

cebe commented Feb 20, 2014

Also in method detail display, we should show whether the method is public or private.

done. 82d103d

cebe added a commit that referenced this issue Feb 20, 2014
@cebe cebe modified the milestones: 2.0 RC, 2.0 Beta Mar 7, 2014
@cebe
Copy link
Member

cebe commented Mar 7, 2014

This is out of scope of the beta, moved to RC.

@cebe cebe modified the milestones: 2.0 GA, 2.0 RC Jun 25, 2014
@cebe cebe modified the milestones: 2.0.1, 2.0 GA Sep 29, 2014
@cebe cebe modified the milestones: 2.0.1, 2.0.x Oct 19, 2014
@cebe cebe removed this from the 2.0.x milestone Jan 24, 2016
@yii-bot
Copy link

yii-bot commented Jan 24, 2016

Issue moved to yiisoft/yii2-apidoc#44

@yii-bot yii-bot closed this as completed Jan 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants