php8.5
Home/ Manual/ yaf / yaf_controller_abstract/ Yaf_Controller_Abstract::getResponse

Yaf_Controller_Abstract::getResponse

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Retrieve current response object

Description

Yaf_Controller_Abstract::getResponse(): Yaf_Response_Abstract|null

Returns the Yaf_Response_Abstract instance associated with this controller.

Parameters Parameters

Return Values

A Yaf_Response_Abstract instance, or null if no response is available.

Examples

Yaf_Controller_Abstract::getResponse example

php
<?php
class ProductController extends Yaf_Controller_Abstract
{
    public function apiAction() {
        // build the answer ourselves, no template needed
        Yaf_Dispatcher::getInstance()->disableView();

        $response = $this->getResponse();
        $response->setHeader("Content-Type", "application/json");
        $response->setBody(json_encode(array("name" => "yaf")));
        // Yaf sends the body after the dispatch loop finishes
    }
}
?>

See Also

  • Yaf_Controller_Abstract::getRequest
  • Yaf_Response_Abstract

Source: reference/yaf/yaf_controller_abstract/getresponse.xml · from the official PHP manual (php/doc-en)