Simplified code:
Model:
/**
* @return array{name:string,age:int,group:int}
*/
public function fetchStudent($id){
//fetch $id student from db and return array
(...)
}
My controller:
$students = $myStudentsModel->fetchStudent(123);
Now in the controller when I try to use code completion in $students variable, the returned array structure is automatically suggested as defined in PHPDoc.
However, when I finally pass it to a view:
return $this->render('student', [
'student' => $student
]);
in the view file the $student variable knows nothing about the array structure it knew when in controller.
I tried different PHPDoc tags (e.g. uses), changing array structure to [#ArrayShape] attribute, pulling params in the view from $this->context - nothing works. PhpStorm 'loses track' of a variable once passed from controller to view.
Do you have any idea how to pass docs alongside variables to views?
* @var array{...} $student. To get passed variables in view templates automatically you will probably need some plugin. I don't know about any plugin that would be able to do that.