|
Posted by Mauricio Araya V. on 05/12/05 03:13
Hello All...
I am having some issues extending from the Smarty class... This is my
scenario (sorry for the large email):
- Since HTML is XML, I want to use XML_Beautifier to beautify my pages code..
[http://pear.php.net/package/XML_Beautifier]
- I am trying to apply an output filter to get that done.
- I am using PHP5,
I've already reading "Classes and Objects (PHP5)" from:
http://www.php.net/manual/en/language.oop5.php
This is the code (I got rid of the comments to make it smaller):
<?php
// myClass.php
function __autoload($class_name) {
require_once ('Smarty.class.php');
require_once ('XML/Beautifier.php');
}
class myClass extends Smarty {
private $template_file='/dev/null';
public function __construct ( ) {
parent::__construct( );
}
public function beautifyCode ($code){
$beauty = new XML_Beautifier( );
return $beauty->formatString($code);
}
public function setCacheDir ($dir='cached'){
$this->cache_dir = $dir;
}
public function setTemplateDir ($dir='templates'){
$this->template_dir = $dir;
}
public function setCompileDir ($dir='compiled'){
$this->compile_dir = $dir;
}
public function setConfigDir ($dir='config'){
$this->config_dir = $dir;
}
public function publishContent ( ){
$this->register_outputfilter(array(&$this, "beautifyCode"));
$this->display($this->template_file);
}
public function setTemplateFile ($file){
$this->template_file = $file;
}
}
?>
Now .. my test:
<?php
//test.php
require_once("myClass.php");
$page = new myClass();
$beauty = new XML_Beautifier( );
$page->setTemplateDir('/path/to/my/templates/');
$page->setCompileDir('/path/tp/my/compiled');
$page->setConfigDir('/path/to/my/config/');
$page->setCacheDir('/path/to/my/cache/');
$page->assign('title', "My Page");
$page->assign('content', "My Content");
$page->setTemplateFile('test.tpl');
$page->publishContent();
?>
.....
- If I comment the line where I register the output filter, first line
at publishContent(),
it works just perfect.
- If I don't comment the line, it prints: "Object id #5".
- If I replace the line with:
$this->register_outputfilter("beautifyCode");
it only prints the following warning:
"Warning: call_user_func_array() [function.call-user-func-array]:
First argument
is expected to be a valid callback, 'beautifyCode' was given in
/paht/tol/my/Smarty/Smarty.class.php on line 1264"
- If I change beautifyCode() to:
public function beautifyCode ($code){
return strtoupper($code);
}
It will work converting the HTML to uppercase.
I know that seing the last example (the uppercase), you are now saying that
this problem does not have anything to do with smarty, but you guys know
better how smarty is built... and maybe someone has had the same issue.
Any hint will be appreciated!
Regards,
-Mauricio
Navigation:
[Reply to this message]
|