source: branches/2.4/prototype/library/tonic/examples/smarty/smarty.php @ 6754

Revision 6754, 1.4 KB checked in by niltonneto, 12 years ago (diff)

Ticket #0000 - Copiadas as alterações do Trunk. Versão final da 2.4.1.

  • Property svn:executable set to *
Line 
1<?php
2
3@include_once 'smarty/Smarty.class.php';
4
5/**
6 * Smarty template example
7 *
8 * Using Smarty for representation generation
9 *
10 * @namespace Tonic\Examples\Filesystem
11 * @uri /smarty
12 */
13class SmartyResource extends Resource {
14   
15    protected $smarty;
16   
17    function __construct() {
18       
19        $this->smarty = new Smarty();
20        $this->smarty->template_dir = '../examples/smarty/representations';
21        $this->smarty->compile_dir = sys_get_temp_dir();
22       
23    }
24   
25    function get($request) {
26       
27        $response = new Response($request);
28       
29        $this->smarty->assign('title', 'Smarty template');
30        $body = $this->render('default');
31       
32        $etag = md5($body);
33        if ($request->ifNoneMatch($etag)) {
34           
35            $response->code = Response::NOTMODIFIED;
36           
37        } else {
38       
39            $response->code = Response::OK;
40            $response->addHeader('Content-type', 'text/html');
41            $response->body = $body;
42           
43        }
44       
45        return $response;
46       
47    }
48   
49    protected function render($view, $format = 'html', $useShell = TRUE) {
50       
51        if ($format == 'html' && $useShell) {
52            $this->smarty->assign('body', $this->smarty->fetch($view.'.'.$format));
53            return $this->smarty->fetch('shell.'.$format);
54        } else {
55            return $this->smarty->fetch($view.'.'.$format);
56        }
57       
58    }
59   
60}
Note: See TracBrowser for help on using the repository browser.