Cake\Network\Response::body PHP Method

body() public method

Buffers the response message to be sent if $content is null the current buffer is returned
public body ( string | callable | null $content = null ) : string
$content string | callable | null the string or callable message to be sent
return string Current message buffer if $content param is passed as null
    public function body($content = null)
    {
        if ($content === null) {
            return $this->_body;
        }
        return $this->_body = $content;
    }

Usage Example

Example #1
7
 /**
  * Instantiates the correct view class, hands it its data, and uses it to render the view output.
  *
  * @param string $view View to use for rendering
  * @param string $layout Layout to use
  * @return \Cake\Network\Response A response object containing the rendered view.
  * @link http://book.cakephp.org/3.0/en/controllers.html#rendering-a-view
  */
 public function render($view = null, $layout = null)
 {
     $builder = $this->viewBuilder();
     if (!$builder->templatePath()) {
         $builder->templatePath($this->_viewPath());
     }
     if (!empty($this->request->params['bare'])) {
         $builder->autoLayout(false);
     }
     $builder->className($this->viewClass);
     $this->autoRender = false;
     $event = $this->dispatchEvent('Controller.beforeRender');
     if ($event->result instanceof Response) {
         return $event->result;
     }
     if ($event->isStopped()) {
         return $this->response;
     }
     if ($builder->template() === null && isset($this->request->params['action'])) {
         $builder->template($this->request->params['action']);
     }
     $this->View = $this->createView();
     $this->response->body($this->View->render($view, $layout));
     return $this->response;
 }
All Usage Examples Of Cake\Network\Response::body