-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Controller::$request and $response #18083
Conversation
0ebe08a
to
0baece2
Compare
@brandonkelly there's #18032 that is more general fix. It's still missing console support (that's why it is not merged yet) but web is fine. |
@samdark That PR seems more focused on DI for controller actions; I don’t see anything about |
Oh, sorry. You're right. It's different. |
@xepozz Those changes don’t seem consistent with other DI components in Yii, e.g. yii2/framework/caching/DbCache.php Lines 42 to 48 in 60a3965
yii2/framework/filters/AccessControl.php Lines 59 to 64 in 60a3965
yii2/framework/filters/PageCache.php Lines 69 to 75 in 60a3965
If their initial values are |
w00t! |
Thanks! |
@samdark , @brandonkelly , we have a problem right after composer update. Exactly here $this->request is a string "request"! |
@justSinner What’s the stack trace? Yii’s built-in CSRF validation is in |
@brandonkelly The request is not an object there at all 2020-06-18 12:42:05 [...][33][ojh39gvi4b5brbqr68bjainrqp][error][yii\base\UnknownPropertyException] yii\base\UnknownPropertyException: Getting unknown property: frontend\controllers\ApiController::request in /.../vendor/yiisoft/yii2/base/Component.php:154 |
Hm, I’m guessing your @samdark do you think I should move the |
@brandonkelly , http://prntscr.com/t23jnr - ApiController extends yii\web\Controller and has no init() method at all. |
Actually, looking at your actual error message, it looks like PHP isn’t seeing the new Make sure that those new properties are actually defined on |
@justSinner it would likely be helpful to start with a clean basic project template and reproduce it. |
I'm sorry, wrong stack trace, a lot of logs... There is stacktrace for this error: 2020-06-18 14:01:28 [127.0.0.1][43][fpbvg0s72ul95c4epfsge8nel5][error][Error] Error: Call to a member function validateCsrfToken() on string in /.../vendor/yiisoft/yii2/web/Controller.php:203 |
There wasn't init() method in yii\web\Controller previously. We've found, that our BaseController has init() method without parent::init(). Thx for quick reply. |
Thanks, figured. So @samdark thoughts on this question? #18083 (comment) We added some logic to Craft’s base web controller’s |
I think UPGRADE is better. |
PR submitted: #18119 |
So I ran composer update on July 08, and my application crashed.
I don't have an Solution on my end has been changing the variable |
Error line: yii2/framework/di/Instance.php Line 126 in 700ac02
@jdprime There’s a risk of this happening any time a new property is added to a base class. Sorry you got bit by it. |
Good to know. Thank you for replying. However I was setting my |
The issue probably is that it is set to The good news is, it sounds like all you really need to do is remove your own |
This version of yii2 add new feature action injection. In our test we need to mock Request class. yiisoft/yii2#18083 https://www.yiiframework.com/news/293/yii-2-0-36
🤦♂️🙂 |
@DmLapin yes, that's fine since Yii 2 still works fine on 5.4. |
|
@azzi907 if you believe there is an error here please report a new issue about it with steps to reproduce it. |
This PR sets
$request
and$response
objects onyii\base\Controller
, adding support for those objects to be dependency-injected (e.g. with a mock object when testing).