예제 #1
0
/**
* Tests the charset method
*
*/
	public function testCharset() {
		$response = new CakeResponse();
		$this->assertEquals($response->charset(), 'UTF-8');
		$response->charset('iso-8859-1');
		$this->assertEquals($response->charset(), 'iso-8859-1');
		$this->assertEquals($response->charset('UTF-16'), 'UTF-16');
	}
예제 #2
0
 /**
  * Sets the response header based on type map index name. This wraps several methods
  * available on CakeResponse. 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 boolean 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.
  * @see RequestHandlerComponent::setContent()
  */
 public function respondAs($type, $options = array())
 {
     $defaults = array('index' => null, 'charset' => null, 'attachment' => false);
     $options = $options + $defaults;
     $cType = $type;
     if (strpos($type, '/') === false) {
         $cType = $this->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 (empty($this->request->params['requested'])) {
         $this->response->type($cType);
     }
     if (!empty($options['charset'])) {
         $this->response->charset($options['charset']);
     }
     if (!empty($options['attachment'])) {
         $this->response->download($options['attachment']);
     }
     return true;
 }