original_string: public function respondAs($type, array $options = [])
      {
          $defaults = ['index' => null, 'charset' => null, 'attachment' => false];
          $options += $defaults;
  
          $cType = $type;
          $controller = $this->getController();
          $response = $controller->getResponse();
          $request = $controller->getRequest();
  
          if (strpos($type, '/') === false) {
              $cType = $response->getMimeType($type);
          }
          if (is_array($cType)) {
              if (isset($cType[$options['index']])) {
                  $cType = $cType[$options['index']];
              }
  
              if ($this->prefers($cType)) {
                  $cType = $this->prefers($cType);
              } else {
                  $cType = $cType[0];
              }
          }
  
          if (!$type) {
              return false;
          }
          if (!$request->getParam('requested')) {
              $response = $response->withType($cType);
          }
          if (!empty($options['charset'])) {
              $response = $response->withCharset($options['charset']);
          }
          if (!empty($options['attachment'])) {
              $response = $response->withDownload($options['attachment']);
          }
          $controller->setResponse($response);
  
          return true;
      }
code: public function respondAs($type, array $options = [])
      {
          $defaults = ['index' => null, 'charset' => null, 'attachment' => false];
          $options += $defaults;
  
          $cType = $type;
          $controller = $this->getController();
          $response = $controller->getResponse();
          $request = $controller->getRequest();
  
          if (strpos($type, '/') === false) {
              $cType = $response->getMimeType($type);
          }
          if (is_array($cType)) {
              if (isset($cType[$options['index']])) {
                  $cType = $cType[$options['index']];
              }
  
              if ($this->prefers($cType)) {
                  $cType = $this->prefers($cType);
              } else {
                  $cType = $cType[0];
              }
          }
  
          if (!$type) {
              return false;
          }
          if (!$request->getParam('requested')) {
              $response = $response->withType($cType);
          }
          if (!empty($options['charset'])) {
              $response = $response->withCharset($options['charset']);
          }
          if (!empty($options['attachment'])) {
              $response = $response->withDownload($options['attachment']);
          }
          $controller->setResponse($response);
  
          return true;
      }
code_tokens: public function respondAs ( $ type , array $ options = [ ] ) { $ defaults = [ 'index' => null , 'charset' => null , 'attachment' => false ] ; $ options += $ defaults ; $ cType = $ type ; $ controller = $ this -> getController ( ) ; $ response = $ controller -> getResponse ( ) ; $ request = $ controller -> getRequest ( ) ; if ( strpos ( $ type , '/' ) === false ) { $ cType = $ response -> getMimeType ( $ type ) ; } if ( is_array ( $ cType ) ) { if ( isset ( $ cType [ $ options [ 'index' ] ] ) ) { $ cType = $ cType [ $ options [ 'index' ] ] ; } if ( $ this -> prefers ( $ cType ) ) { $ cType = $ this -> prefers ( $ cType ) ; } else { $ cType = $ cType [ 0 ] ; } } if ( ! $ type ) { return false ; } if ( ! $ request -> getParam ( 'requested' ) ) { $ response = $ response -> withType ( $ cType ) ; } if ( ! empty ( $ options [ 'charset' ] ) ) { $ response = $ response -> withCharset ( $ options [ 'charset' ] ) ; } if ( ! empty ( $ options [ 'attachment' ] ) ) { $ response = $ response -> withDownload ( $ options [ 'attachment' ] ) ; } $ controller -> setResponse ( $ response ) ; return true ; }
docstring: Sets the response header based on type map index name. This wraps several methods
  available on Cake\Http\Response. It also allows you to use Content-Type aliases.
  
  @param string|array $type Friendly type name, i.e. 'html' or 'xml', or a full content-type,
  like 'application/x-shockwave'.
  @param array $options If $type is a friendly type name that is associated with
  more than one type of content, $index is used to select which content-type to use.
  @return bool Returns false if the friendly type name given in $type does
  not exist in the type map, or if the Content-type header has
  already been set by this method.
docstring_tokens: Sets the response header based on type map index name . This wraps several methods available on Cake \ Http \ Response . It also allows you to use Content - Type aliases .