Cakephp Classroom image

pankaj
 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24|Last
Lessons:-Controllers

$this->response->vary(’User-Agent’);
$this->response->vary(’Accept-Encoding’, ’User-Agent’);
$this->response->vary(’Accept-Language’);
CakeResponse and testing
Probably one of the biggest wins from CakeResponse comes from how it makes testing controllers and
components easier. Instead of methods spread across several objects, you only have a single object to mock
as controllers and components delegate to CakeResponse. This helps you get closer to a ‘unit’ test and
makes testing controllers easier:
public function testSomething() {
$this->controller->response = $this->getMock(’CakeResponse’);
$this->controller->response->expects($this->once())->method(’header’);
// ...
}
Additionally you can more easily run tests from the command line, as you can use mocks to avoid the
‘headers sent’ errors that can come up from trying to set headers in CLI.
CakeResponse API
class CakeResponse
CakeResponse provides a number of useful methods for interacting with the response you are sending
to a client.
CakeResponse::header($header = null, $value = null)
Allows you to directly set one or many headers to be sent with the response.
CakeResponse::charset($charset = null)
Sets the charset that will be used in the response.
CakeResponse::type($contentType = null)
Sets the content type for the response. You can either use a known content type alias or the full content
type name.
CakeResponse::cache($since, $time = ‘+1 day’)
Allows you to set caching headers in the response.
CakeResponse::disableCache()
Sets the headers to disable client caching for the response.
CakeResponse::sharable($public = null, $time = null)
Sets the Cache-Control header to be either public or private and optionally sets a max-age directive
of the resource New in version 2.1.
CakeResponse::expires($time = null)
Allows to set the Expires header to a specific date. New in version 2.1.
CakeResponse::etag($tag = null, $weak = false)
Sets the Etag header to uniquely identify a response resource. New in version 2.1.CakeResponse::modified($time = null)
Sets the Last-Modified header to a specific date and time in the correct format. New in version 2.1.
CakeResponse::checkNotModified(CakeRequest $request)
Compares the cache headers for the request object with the cache header from the response and determines
if it can still be considered fresh. In that case deletes any response contents and sends the 304
Not Modified header. New in version 2.1.
CakeResponse::compress()
Turns on gzip compression for the request.
CakeResponse::download($filename)
Allows you to send the response as an attachment and set the filename.
CakeResponse::statusCode($code = null)
Allows you to set the status code for the response.
CakeResponse::body($content = null)
Set the content body for the response.
CakeResponse::send()
Once you are done creating a response, calling send() will send all the set headers as well as the body.
This is done automatically at the end of each request by Dispatcher
CakeResponse::file($path, $options = array())
Allows you to set a file for display or download New in version 2.3.

 
 
 

pankaj

Skills    Cakephp

Qualifications :-
Location :-,,,
Description:-
Explore
 

  Students (0)