yii2support
yii2support copied to clipboard
View require variable bug
Hi!
In my view used a static variable from class instance, e.g:
$modelPayment::$typeDefault => 'Use as my mailing address'
But around "render" method call in my controller I see error "View require typeDefault parameter".
Thanx!
Hi! Bug is actually in latest releace?
Yeap.
Please send using variable code part for test and IDE version
IDE version: 2017.1
signup.php
... [ $modelPayment::$typeDefault => 'Type default', ... ] ...
signup.php
$modelPayment = new ModelPayment();
$typeDefault = '123123';
$typeDefault2 = '123123';
$tmp = [
$modelPayment::$typeDefault => '123123',
$modelPayment::$typeDefault2 => '123123',
];
$this->render('signup', ['loginForm' => $loginForm])
inspection is not mark this code as error
He ment that key stored in constant. I acquire this bug.
I see a close bug. Plugin shows my view requires variables:
but really these variables are just parameters of closure:
PhpStorm 2017.1.4
Thanks for your contribution.
Also, if in the view file I have something like this:
if (!isset($items)) {
$items = [];
}
Then I don't think the $items
variable should be required. Is it possible?
v. 0.10.57.23
public function actionTest(): string {
return $this->render('test', [
'data' => Test::test()
]);
}
This View does not use parameters
However, the variable is used. I use DatePicker widget
<?= DatePicker::widget([
'name' => 'date',
'pluginOptions' => [
'startDate' => array_shift($data),
'endDate' => array_pop($data)
]
]); ?>
Looks like this has been left for some time (appreciate the project hasn't been worked on for a while). However, like a number of issues still open here, the main problem here seems to have been fixed. At least, a closure in a view with arguments does not cause a warning that required parameters are not sent.
What is still broken is the behaviour described by @pappfer where view parameters cannot be optional. This is a real pain as it is common to use optional parameters in partials or shared views.
To fix this, I suggest that type annotations that could be null should not cause warnings, e.g. in view:
/* @var $this \yii\web\View */
/* @var $email string */
/* @var $name string|null */
...
Then render call as follows should not show a warning:
$this->render('my-view', [
'email' => '[email protected]',
]);
@spikyjt doesn't seem to work for me. Even if I put type annotations in my view, the render()
method is still highlighted in red in the controller saying it requires that parameter.
@pappfer please read my comment. I said that the behaviour you previously described still doesn't work. I then made a suggestion to improve it, but that has not been implemented yet. Are you saying closure arguments or class static vars still cause a warning?