Example of rendered view cache as html

class HtmlCacheHelper extends AppHelper {
  function afterLayout() {
    $view =& ClassRegistry::getObject('view');

    //handle 404s
    if ($view->name == 'CakeError') {
      $path = $this->params['url']['url'];
    } else {
      $path = $this->here;
    }

    $path = implode(DS, array_filter(explode('/', $path)));
    if($path !== '') {
      $path = DS . ltrim($path, DS);
    }
    $path = WWW_ROOT . 'backup' . $path.'.html';

    $file = new File($path, true);
    $file->write($view->output);
  }
}

On Jun 5, 5:30 pm, qwanta <[email protected]> wrote:
> Experimenting a bit more, it seems that another straightforward way to
> do this is use the php function "file_get_contents" to get a string
> with the view.
> The advantage is that any view can be accessed even in a different
> cake app (as mine is).
>
> On Jun 5, 10:13 am, qwanta <[email protected]> wrote:
>
> > Thanks brian. I didn't know render returned a string - I had looked up
> > the function in the book (where the return val isn't documented) but
> > not in the source code.
>
> > On Jun 4, 12:47 pm, brian <[email protected]> wrote:
>
> > > Have a look at Controll:render() method. It returns a string that you
> > > could write to a file. However, I'm not sure how that might affect
> > > also rendering the same view to the browser.
>
> > >http://api.cakephp.org/view_source/controller/#line-755http://book.ca...
>
> > > I suppose, if for some reason, calling render() twice (once manually,
> > > to save your file, and again automatically, as usual) will mess things
> > > up for the browser output, you could write the string to a file, then
> > > echo the same string. You might have to set the appropriate headers,
> > > though.
>
> > > But that's all speculation. Try calling render yourself to write to
> > > the file and see if Cake wwill still call it automatically for browser
> > > output, as normal.
>
> > > On Wed, Jun 3, 2009 at 8:10 PM, qwanta <[email protected]> wrote:
>
> > > > I am drawing a blank on this one, any help appreciated. Basically my
> > > > view is a calibration record that also needs to be saved in a folder
> > > > for backup purposes. Is it possible to save the view as an htm file,
> > > > just as if you selected "Save Page As" in Firefox?
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to