Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

bug in block_function handling?
Hej folks,

I think I stumbled into a bug of the handling of block functions.
Anyhow I need some clarification and the manual can possibly also be clearer
in some points.

I have written a block function that I want to keep uncacheable.

the function is written in a file named:
block.php_component_nc.php

the function itself is named like below:

function smarty_block_php_component_nc($params, $content, &$this)
{
extract($params,EXTR_SKIP);
..
return $component_output;
}

inside my php application it is included and registered by doing:

include_once('Smarty/Smarty_nocache_cmpt/block.php_component_nc.php');//on
the include dir path
$smartyDisplay->register_block('php_component_nc', 'php_component_nc',
false);

Now if I run it with:
$this->caching=false;

everything is all right but when
$this->caching=true;

I get:
Fatal error: Smarty error: [in candidate/it.tpl line 29]: [plugin] could not
load plugin file 'block.php_component_nc.php' (core.load_plugins.php, line
118) in /usr/share/munk_php/Smarty-2.6.6/libs/Smarty.class.php on line 1088

For completness my extended smarty function contains:
$this->Smarty();
$this->template_dir = SMARTY_DIR . 'Smarty_templates/job.eaktion.com';
$this->config_dir=SMARTY_DIR . 'Smarty_configs/job.eaktion.com/akaCMS';
$this->cache_dir=SMARTY_DIR . 'Smarty_cache/job.eaktion.com';
$this->compile_dir=SMARTY_DIR . 'Smarty_templates_c/job.eaktion.com';
$this->plugins_dir=array(SMARTY_DIR .'plugins',SMARTY_DIR .
'Smarty_custom_plugins');
$this->debugging = false;
$this->debugging_ctrl = 'URL';
$this->compile_check=true;
$this->force_compile=false;
$this->caching=true;
$this->cache_lifetime=3600;


Actually I found a way to make it work and it is the following:
including the file as stated above with:
include_once('Smarty/Smarty_nocache_cmpt/block.php_component_nc.php')
but also keeping the same file inside the custom_plugins dir. In this way
the file is found (as a custom plugin), and the function is registered (as a
registered function). To make the trick really work though and avoid a:
Fatal error: Cannot redeclare smarty_block_php_component_nc() (previously
declared in
/usr/share/munk_php/Smarty/Smarty_custom_plugins/block.php_component_nc.php

the function declared inside the file not in the custom_plugins dir has to
be declared as:
php_component_nc (and not smarty_block_php_component_nc)

If I omit the block.php_component_nc.php file from my custom_plugins dir I
get:
Fatal error: Smarty error: [in candidate/it.tpl line 29]: [plugin] could not
load plugin file 'block.php_component_nc.php' (core.load_plugins.php, line
118) in /usr/share/munk_php/Smarty-2.6.6/libs/Smarty.class.php on line 1088

Trying to make this work I've been reading the manual several times to find
an error in what I was doing, and I found places where there are mistakes or
typos (in the manual):

I assume the naming conventions are correct
<quote>The plugin functions inside the plugin files must be named as
follows:
smarty_type_name()
</quote>

, but then in the example 1 at:
http://smarty.php.net/manual/en/api.register.block.php

<quote>
Example 1. register_block

<?php
$smarty->register_block("translate", "do_translation");

function do_translation ($params, $content, &$smarty, &$repeat)
{
if (isset($content)) {
$lang = $params['lang'];
// do some translation with $content
return $translation;
}
}
?>
</quote>

The name of the function in the example should be
smarty_block_do_translation()


The same happens in page:
http://smarty.php.net/manual/en/caching.cacheable.php

<quote>
Example 13-10. Preventing a plugin's output from being cached

<?php
require('Smarty.class.php');
$smarty = new Smarty;
$smarty->caching = true;

function remaining_seconds($params, &$smarty) {
$remain = $params['endtime'] - time();
if ($remain >=0)
return $remain . " second(s)";
else
return "done";
}

$smarty->register_function('remaining', 'remaining_seconds', false,
array('endtime'));

if (!$smarty->is_cached('index.tpl')) {
// fetch $obj from db and assign...
$smarty->assign_by_ref('obj', $obj);
}

$smarty->display('index.tpl');
?>
</quote>

where the function should be declared as:
smarty_function_remaining_seconds

a couple of lines below we find what I guess is a typo
<quote>
where index.tpl is:

Time Remaining: {remain endtime=$obj->endtime}
</quote>

It should be:
{remaining endtime=$obj->endtime}

One more example is provided on the same page and here the error is in the
way the function gets registered:

<quote>
Example 13-11. Preventing a whole passage of a template from being cached

index.php:

<?php
...

function smarty_block_dynamic($param, $content, &$smarty) {
return $content;
}
$smarty->register_block('dynamic', 'smarty_block_dynamic', false);
</quote>

The function should be registered as :
$smarty->register_block('dynamic', 'dynamic', false);


I hope for myself that all this is not the result of my lack of sleeping
time.
If you found the mistake in what I do please tell me, otherwise I'm sure
you'll fix the bug.

Anyhow I won't ever be able to thank you enough for this terrific
application.

Greets
Paolo

Report this thread to moderator Post Follow-up to this message
Old Post
Paolo Nesti Poggi
10-20-04 09:08 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Smarty Templates archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:25 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.