1

I'm trying to extend the Request component of Yii2 as our previous Yii1 project extended CHttpRequest, but all I get is a 500 error no matter what I try. My config is as follow:

'components' => [
    'request' => [
        'class' => 'app\components\MY_HttpRequest',
        'cookieValidationKey' => '...',
    ],
    ...
],

Then in //components/MY_HttpRequest.php, even with an empty class that would just call the parent's method:

<?php

//namespace app\components;
namespace app\components\MY_HttpRequest;

use Yii;

class MY_HttpRequest extends yii\web\Request {
}

It displays a 500 error, so I can't really debug this as I don't have any feedback. I searched on Google how to extend the Request component but all I found was a question on how to extend the Response component, and I'm already using that method with no success.

There are no details about the error (Only using example.com as example): enter image description here

Moreover, if I change this line like such:

'class' => 'app\components\MY_HttpRequestaaaaaaaaaaaaaa',

I get an error that the file is not found, so I know the file is being loaded.

NaturalBornCamper
  • 3,675
  • 5
  • 39
  • 58

2 Answers2

1

Change your class and file name to MYHttpRequest and it will be work

'components' => [
    'request' => [
        'class' => 'app\components\MYHttpRequest',
        'cookieValidationKey' => '...',
    ],
]

And components/MYHttpRequest.php

namespace app\components;

class MYHttpRequest extends \yii\web\Request {

}
Denis Ostrovsky
  • 519
  • 1
  • 6
  • 16
0

Turn out I had just forgotten a tiny backslash in my "extend" statement.

class MY_HttpRequest extends yii\web\Request

Should have been

class MY_HttpRequest extends \yii\web\Request
NaturalBornCamper
  • 3,675
  • 5
  • 39
  • 58