Re: [SMARTY] register_function and Objects

From: Date: Wed, 28 Aug 2002 11:52:39 +0000
Subject: Re: [SMARTY] register_function and Objects
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-5853@lists.php.net to get a copy of this message
I tried this method, and while it would've worked it required me to step outside the level of abstraction that I wanted to keep ; I messed around with the smarty.class.php and smart_compiler.class.php files to get it to work the way I wanted. Figured this might be useful to anyone else doing something similar ( worth noting this is from 2.2.0 ): Once you've changed the code, you can use the same old: $_SMARTY->register_function("alias",Array($obj_ref,"real_function")); syntax. /*======================================================================*\ Function: _load_plugins Purpose: Load requested plugins Location: Smarty.class.php \*======================================================================*/ // ...this is from the first statement block within the foreach() loop // of _load_plugins if (isset($plugin)) { if (!$plugin[3]) { if(is_array($plugin[0])){ $fname=$plugin[0][1]; $obj=$plugin[0][0]; } else { $fname=$plugin[0]; $obj=false; } // ...before it was incorrectly assigning the variables // if $plugin[0] was an array /*======================================================================*\ Function: _compile_custom_tag Purpose: compile custom function tag Location: Smarty.compiler.class.php \*======================================================================*/ // ...replace the return statement at the end of the function with this // block of code if(is_array($this->_plugins['function'][$tag_command][0])) $ostring="\$obj=\$this->_plugins['function']['$tag_command'][0][0];\$obj->".$this->_plugins['function'][$tag_command][0][1]; else $ostring="\$this->_plugins['function']['$tag_command'][0]"; return "<?php ".$ostring."(array(".implode(',', (array)$arg_list)."), \$this); if(\$this->_extract) { extract(\$this->_tpl_vars); \$this->_extract=false; } ?>"; // ... CZ, who notes that adding a notice in the docs might be useful as well.

« previous php.smarty.general (#5853) next »