Why buffer when connecting a template? Sorry for the "stupid" question, just do not understand this moment. And if you do not do buffering, will everything be bad?) Thanks in advance for the answer!

class View { function render($tpl, $data) { extract($data); ob_start(); include $tpl; return ob_get_clean(); } } 
  • @vinnie> Why buffer when a template is connected? To save the output to a variable and subsequently process it. > And if you do not do buffering, will everything be bad? No, but the ability to work with ready-made content will disappear. For example, it will not be possible to separately render the view and then insert it into the layout. - etki
  • How and where is better to determine the layout? - vinnie
  • @vinnie, are you sure you need him at this stage? In Yii, this is just the same view file, the view is first rendered, substituted into the $ content variable, and then the layout is rendered, in which the output of the $ content variable is assumed. Layouts are in the same place as view. - etki
  • I mean, you can also assign the output to a variable without buffering. Class View {function render ($ tpl, $ data) {extract ($ data); $ content = include $ tpl; }} - vinnie
  • @vinnie, only if the file is return 'большая-большая строка'; . If something is displayed in the file, it will not fall into the variable. - etki

0