source: Dev/branches/rest-dojo-ui/server/tonic/examples/smarty/smarty.php @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 1.4 KB
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.