|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Kman Smarty n00b
Joined: 20 Jul 2003 Posts: 3
|
Posted: Sun Jul 20, 2003 3:40 pm Post subject: using register_function with functions within a class |
|
|
hi!
I'm having trouble to do something that's a bit hard to explain.. but here goes:
I'm trying to register a function witch is placed within a class, like so:
Code: | <?php
require('Smarty.class.php');
class TemplateParser extends Smarty
{
var $base;
function TemplateParser()
{
$this->Smarty();
$this->template_dir = '/home/kman/public_html/tcgo/smarty_templates/';
$this->compile_dir = '/home/kman/public_html/tcgo/smarty_templates_c/';
$this->config_dir = '/home/kman/public_html/tcgo/smarty_configs/';
$this->cache_dir = '/home/kman/public_html/tcgo/smarty_cache/';
}
function registerBaseObject($baseObject)
{
$this->base = $baseObject;
}
}
class Base
{
var $templateParser;
function Base($templateParserObject)
{
$this->templateParser = $templateParserObject;
$this->templateParser->registerBaseObject($this);
$this->templateParser->register_function("base_loadModule", "$this->loadModules_smarty");
$this->templateParser->display($this->templateParser->template_dir.'news.tpl');
}
function loadModules_smarty($params)
{
extract($params);
print "$name";
}
}
$templateParser = new TemplateParser();
$base = new Base($templateParser);
?> |
news.tpl:
When I start the above .php script, I get an error saying that the ' function 'base_loadModule' is not implemented'. How do I get the named function implemented?
I know I can use register_object, or let the templates use $base->loadModule, but I have a certain structure and features in mind that need the option to reference functions to simpler names and lesser complicated template-entries, whitch register_function provides.
I've tried $this->base->loadModules_smarty as 2nd parameter of register_function, as that's the way to reach the function for the TemplateParser class, but that didn't work ether). Just entering loadModules_smarty as 2nd parameter also doesn't work.
Anyone got a suggestion? |
|
Back to top |
|
AZTEK Smarty Pro
Joined: 16 Apr 2003 Posts: 235 Location: Purdue University
|
Posted: Sun Jul 20, 2003 5:40 pm Post subject: |
|
|
Instead of [php:1:f7d410261b]$this->templateParser->register_function("base_loadModule", "$this->loadModules_smarty");[/php:1:f7d410261b]try[php:1:f7d410261b]$this->templateParser->register_function("base_loadModule", array(&$this, "loadModules_smarty"));[/php:1:f7d410261b]it might work depending on how Smarty calls the function I havn't actually looked in CVS yet. _________________ "Imagine a school with children that can read and write, but with teachers who cannot, and you have a metaphor of the Information Age in which we live." -Peter Cochrane |
|
Back to top |
|
Kman Smarty n00b
Joined: 20 Jul 2003 Posts: 3
|
Posted: Sun Jul 20, 2003 5:55 pm Post subject: |
|
|
thanks for the reply, didn't work though . Keep getting the same error: Quote: | Fatal error: Smarty error: [in /home/kman/public_html/tcgo/smarty_templates/news.tpl line 1]: [plugin] function 'base_loadModule' is not implemented (Smarty.class.php, line 2463) in /usr/lib/php/includes/Smarty/Smarty.class.php on line 2653 |
|
|
Back to top |
|
Kman Smarty n00b
Joined: 20 Jul 2003 Posts: 3
|
Posted: Tue Jul 22, 2003 10:16 pm Post subject: |
|
|
yaay, with the latest (unstable) version from the CVS, your suggestion works
When is this magic going to get an official version number? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Jul 22, 2003 10:46 pm Post subject: |
|
|
No official word on a release date for the CVS code. I'm more concerned about a thorough bug shakeout than speed considering the scope of changes that have been made. I think A LOT of progress has been made on both fronts so if people are willing to TEST the CVS, that is A Good Thing (TM). The CVS should NOT be used for any production systems.
In the meantime, you can create and register local proxy or stub functions which defer to your class methods. I know it is messy but it should put you in a good position for when the new release is made and in the meantime, it should work.
I think it would be neat if we could simply pass an object having each of its functions automatically registered. I think that would require some naming conventions ala the API but I can see some advantadges. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|