📜 ⬆️ ⬇️

Smarty in the view-driven model

Usually the Smarty template engine is applied like this: you write code that creates a data set for a template, give it along with the name of a smarti template and that “connects brands”, outputting the result to the browser.

This is the so-called model with leading controllers. That is, the controller is fully responsible for receiving the templating engine and generally commanding everything.

There is also a model with leading views. In it, the view says to the controller, “but give me, dear friend, a list of recent posts,” after which the controller pulls the model, extracts this list, processes it and gives it to the view (in our case, the template engine).
')
None of these models is the best, in different cases it is convenient to use one or the other. However, smart-out-of-the-box can work only according to the first scheme. Teaching him to work more and the second turned out to be quite easy.

<?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  1. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  2. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  3. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  4. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  5. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  6. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  7. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  8. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  9. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  10. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  11. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  12. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  13. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  14. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  15. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  16. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  17. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  18. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  19. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  20. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  21. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  22. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  23. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  24. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  25. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  26. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  27. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  28. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  29. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  30. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  31. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  32. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  33. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  34. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  35. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  36. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  37. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  38. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  39. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  40. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  41. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  42. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  43. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  44. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  45. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  46. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  47. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  48. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  49. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  50. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  51. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  52. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  53. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  54. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  55. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  56. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  57. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  58. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  59. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  60. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  61. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  62. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  63. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  64. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  65. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  66. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  67. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  68. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  69. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  70. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  71. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
  72. <?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .
<?php /** * index.php * * View-driven smarty usage sample * * Use {data id="SOMEID" var="TPLVAR"} construction in template * to fetch data for template. Return of the DataFetcher object * will be assigned to the variable with TPLVAR name. * * DataFetcher object must have function called fetch() with only * parameter which value will be SOMEID. * * Smarty included in this archieve only for your convenience. * * Remember: it's just a sample * * @copyright (c) Gregory Sitnin, 2009. All rights reserved. * @author Gregory Sitnin <gregor@gregor.ru> * */ $config[ 'base' ] = dirname(__FILE__); $config[ 'tmp' ] = $config[ 'base' ]. '/tmp' ; final class DataFetcher extends ConfiguratedObject { function fetch($name) { return 'Hello, World!' ; } } final class SmartyRender extends ConfiguratedObject { private $smarty; function __construct($config) { parent::__construct($config); require_once $ this ->config[ 'base' ]. '/smarty/Smarty.class.php' ; $ this ->smarty = new Smarty(); $ this ->smarty->template_dir = $ this ->config[ 'base' ]; $ this ->smarty->compile_dir = $ this ->config[ 'tmp' ]; $ this ->smarty->register_function( 'data' , array ($ this , 'getDataProxy' )); } public function getDataProxy($ params , &$smarty) { if (!isset($ params [ 'id' ])) { $smarty->trigger_error( "data: id parameter must be set." ); } elseif (!isset($ params [ 'var' ])) { $smarty->trigger_error( "data: var parameter must be set." ); } else { try { $fetcher = new DataFetcher($ this ->config); $smarty->assign($ params [ 'var' ], $fetcher->fetch($ params [ 'id' ])); } catch (Exception $e) { $smarty->trigger_error( 'data: (' .$e->getCode(). ')' .$e->getMessage()); } } } function render($template, array $vars = null ) { $ this ->smarty->assign($vars); return $ this ->smarty->fetch($template); } } final class App extends ConfiguratedObject { function run() { $render = new SmartyRender($ this ->config); echo $render->render( 'index.tpl' ); } } abstract class ConfiguratedObject { protected $config; function __construct($config) { $ this ->config = $config; } } $app = new App($config); $app->run(); ?> * This source code was highlighted with Source Code Highlighter .

An interesting thing happens on lines 41-57. Using the $ smarty-> register_function () method, I declared a new function of the data template. When this construct is found in a template, the $ this-> getDataProxy () method of the SmartyRender object is called.

The input to the method is a reference to an array of parameters specified in the template and a reference to the smarty object, which operates on the template that called the smarty function.

There is no magic like this. We check the parameters and, if everything is fine with them, then we create an instance of the DataFetcher class. The result of calling the fetch () method of the DataFetcher object will become a template variable, which you can then use as you like.

The template itself in my case looks like this:

  1. < html >
  2. < head >
  3. < title > View-driven Smarty test </ title >
  4. </ head >
  5. < body >
  6. {data id = "test" var = "test"}
  7. Fetched: {$ test}
  8. </ body >
  9. </ html >
* This source code was highlighted with Source Code Highlighter .

The working code of this example (includes Smarty): http://gregor.ru/files/blog/vdsmarty.zip

Source: https://habr.com/ru/post/60561/


All Articles