On the controller side, I get the data and send it as an array into the view. In the form of an array starting to make cards of goods. I am trying to make the logic of creating a card in a separate form, to create a function so that you can

$this->layout = false; return $this->render('page', compact('data')); 

get ready HTML and embed it where needed. I tried to write static functions on the controller side and call them out of sight, but it’s not so good. And it begins that static functions cannot access non-static functions, etc. And in the static method does not work $this->layout = false; and everything related to $this .

In a word, how to be? How can you implement?

  • And what prevents to call directly from the view in the right place <?= $this->render('card_item') ?> ? - pa3py6aka
  • @ pa3py6aka. Thank. Something I was too wise ... Will you make out the answer? - n.osennij
  • Issued an answer .. - pa3py6aka

2 answers 2

You just need to create a separate view with the product card, and in other views in any right place insert it: <?= $this->render('card_item', ['good' => $good]) ?>

    You can make the widget more. If, for example, there will be a card in different controls.

    • Best answer ever! The author of the answer fumbles! He deserves more reputation! - Dmitry Matvienko
    • And what prevents to use the same single view for the card in different controllers? - pa3py6aka
    • Technically there is nothing, logically there will be a file common to several controllers and lying in an incomprehensible folder. - ErroR