パフォーマンス駆動型モデルのSmarty

通常、Smartyテンプレートエンジンはこのように使用されます。テンプレートのデータセットを作成するコードを記述し、smartiにテンプレート名を付け、その1つが「ブランドを接続」し、結果をブラウザーに出力します。

これは、主要なコントローラーを備えたいわゆるモデルです。 つまり、コントローラーは、テンプレートエンジンを受信し、通常はすべてにコマンドを送信するという事実に完全に責任を負います。

一流のパフォーマンスを備えたモデルもあります。 その中で、ビューはコントローラーに「Give me、親愛なる、最近の投稿のリスト」と伝え、その後コントローラーはモデルを取得し、このリストを抽出して処理し、ビュー(この場合はテンプレートエンジン)に渡します。

これらのモデルはどれも最適ではありません。異なる場合には、どちらか一方を使用すると便利です。 それにもかかわらず、箱のスマートアウトは、最初のスキームに従ってのみ機能します。 彼に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 .
  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 .

41〜57行目で興味深いことが起こります。 $ smarty-> register_function()メソッドを使用して、「data」という新しいテンプレート関数を宣言しました。 テンプレート内でこの構造が検出されると、SmartyRenderオブジェクトの$ this-> getDataProxy()メソッドが呼び出されます。

このメソッドは、テンプレートで指定されたパラメーターの配列へのリンクと、スマート関数を呼び出したテンプレートを操作するsmartyオブジェクトへのリンクを取得します。

ここでもそれ以降でも、魔法はありません。 パラメーターを確認し、すべてが問題なければ、DataFetcherクラスのインスタンスを作成します。 DataFetcherオブジェクトのfetch()メソッドを呼び出した結果は、テンプレート変数になり、必要に応じて使用できます。

私の場合、テンプレート自体は次のようになります。

  1. < html >
  2. < >
  3. < title >ビュー駆動のSmartyテスト</ title >
  4. </ >
  5. < 本体 >
  6. {data id = "test" var = "test"}
  7. 取得済み:{$ test}
  8. </ body >
  9. </ html >
*このソースコードは、 ソースコードハイライターで強調表示されました。

この例の作業コード(Smartyを含む): http : //gregor.ru/files/blog/vdsmarty.zip

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


All Articles