Answer the question
In order to leave comments, you need to log in
Is using compact to pass models to the view a good idea or vice versa?
Now, at work, I delve into one large project, where there is a lot where the method of transferring models to a view via compact is used, which makes arrays from objects:
return $this->render('main-view', compact('comInfo', 'SearchingForm',
'revCompany', 'modelComment', 'insuranceType'));
Answer the question
In order to leave comments, you need to log in
return $this->render('main-view', ['comInfo' => $comInfo, 'SearchingForm' => $SearchingForm,
'revCompany' => $revCompany, 'modelComment' => $modelComment, 'insuranceType' => $insuranceType]);
Your question itself sounds one at a time, and the description of the question leads to another discussion.
About compact: Mark Safronov's book recommends this transfer method. It rarely occurs in practice. As far as I remember, PhpStorm does not pick up such a thing and then swears - perhaps the only negative.
And about this - well, yes, you are right, it is strange to pass both arrays and objects that can be reduced to these arrays. But maybe this is how you understood the code, but in fact the idea was deeper. Without the code itself, you can’t tell if it makes sense to do this or not
passing models to view via compact
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question