الدرس الثانى عشر فى الكيك

CakeResponse:

(1) Dealing with content types: You can control the Content-Type of your application’s responses with using CakeResponse::type() and If your application needs to deal with content types that are not built into CakeResponse, you can map those types with type() as well:

// Add a vCard type

$this->response->type(array(’vcf’ => ’text/v-card’));

// Set the response Content-Type to vcard.

$this->response->type(’vcf’);

(2) Sending files: when you want to send files as responses for your requests you can use CakeResponse::file() to send a file as response:

public function sendFile($id) {

$file = $this->Attachment->getFile($id);

$this->response->file($file[’path’]);

//Return reponse object to prevent controller from trying to render a view

return $this->response;

{

(3) Sending a string as file: To send a file as response which does not exist on disk you can do that by using:

public function sendIcs() {

$icsString = $this->Calendar->generateIcs();

$this->response->body($icsString);

$this->response->type(’ics’);

//Optionally force file download

$this->response->download(’filename_for_download.ics’)

//Return response object to prevent controller from trying to render a view

return $this->response;

{

(4) Setting headers: Setting headers is done with the CakeResponse::header() method as:

$this->response->header(’Location’, ’http://example.com’);

(5)Interacting with browser caching: You sometimes need to force browsers to not cache the results of a controller action is intended for just that:CakeResponse::disableCache():

public function index() {

// do something.

$this->response->disableCache();

{

You can also tell clients that you want them to cache responses. By CakeResponse::cache():

public function index() {//do something

$this->response->cache(’-1 minute’, ’+5 days’);

{

وسوف يتم شرح الاكواد السابقة اكثر فى حين التعرض اليها اثناء المشروع.

Advertisements

ضع تعليقك هنا

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: