A
A
AlikDex2016-07-23 13:27:19
Yii
AlikDex, 2016-07-23 13:27:19

How do you pass data to templates?

Actually a question. Just separate pieces, or collect 1 array for example. and transmit?
Well, for example, we create a profile editing page, collect the necessary models in the controller, and add them to the template:

return $this->render('profile', [
  'user' => $user,
  'profile' => $profile,
  'passwordForm' => $passwordForm,
  'avatar' => $avatar,
]);

Or maybe a friend:
$data = [
  'user' => $user,
  'profile' => $profile,
  'passwordForm' => $passwordForm,
  'avatar' => $avatar,
];
return $this->render('profile', [
  'data' => $data,
]);

Well, I wonder why one or the other option is better?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2016-07-23
@AlikDex

Is there a difference? The choice of this or that method should be justified by something. Which is faster, which is easier to read? Which is more convenient. In my opinion, there is no point in an array, it is less flexible and requires extra code, then why? But in your architecture it can be justified.

S
Stanislav, 2016-07-24
@Stasgar

return $this->render('profile', [  'user' => $user,  'profile' => $profile,  'passwordForm' => $passwordForm,  'avatar' => $avatar,]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question