These are the Controller Action Helpers included in the Xyster distribution. For information about Action Helpers themselves, see the documentation for Action Helpers.
It's a pain to have to remember all the HTTP headers associated with Caching responses. It's even more of a pain to remember when certain headers don't work (such as certain browsers over SSL). The Cache helper aims to alleviate some of these concerns.
It has one method, checkModifiedSince
, which is also called by the
direct method of the Helper. Given an integer timestamp, this class compares it to the
IF_MODIFIED_SINCE header sent by the client. If the client has a date that is equal to the
one supplied, the helper sends the proper Not-Modified headers, turns off the
viewRenderer
helper, and returns true. If the client has a date older than the one supplied, the helper
sends the proper cache headers with the date given and returns false.
Here's an example of this class at work in a controller action.
<?php public function fooAction() { $myContentWasModified = time(); if ( $this->_helper->Cache($myContentWasModified) ) { return; } // do content construction here... }
You know what else is a pain? Dynamic file output to a client. Each client is a little different with its gripes about the headers it receives, but this helper should work for most of them.
It has one method, setFileHeaders
, which is also called by the
direct method of the helper. You can supply a filename, a MIME type, and a last modified
integer timestamp of the file (only the filename is required). If the date is specified,
this helper will in turn call the Cache Helper to send correct headers. This plugin will
send the headers needed for the content type and filename, but sending the actual body of
the file and the content length is up to you.
<?php public function fooAction() { $filename = '/tmp/somefile.png'; $myContentWasModified = filemtime($filename); if ( $this->_helper->File(basename($filename), 'image/png', $myContentWasModified) ) { return; } $this->getResponse()->setHeader('Content-Length', filesize($filename)) ->sendHeaders(); fpassthru($filename); }