I
I
Ilya Beloborodov2017-02-28 01:29:12
Yii
Ilya Beloborodov, 2017-02-28 01:29:12

Which method generates html output in yii2?

There is a need to process all the source code before giving it to the browser.
in yii1 i just inherited the render() method of the CController class

<?php

class Controller extends CController
{
  

  public function render($view,$data=null,$return=false){
    if($this->beforeRender($view)){
      $output=$this->renderPartial($view,$data,true);
      if(($layoutFile=$this->getLayoutFile($this->layout))!==false){
        $output=$this->renderFile($layoutFile,array('content'=>$output),true);
      }

      $this->afterRender($view,$output);
      $output=$this->processOutput($output);
      	}

    if($return)
      return $output;
    else
      echo $output;
        
    }
  }

}

how about in yii2?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2017-02-28
@qonand

The controller delegates view rendering to the view itself . Actually it is engaged in the formation of content.
But in general, overriding the render method is not a good practice. If you need to do something with the content, it is better to use for this event or response formatting

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question