|
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 |
andre85 Smarty n00b
Joined: 06 May 2013 Posts: 2
|
Posted: Mon May 06, 2013 1:44 pm Post subject: Problem mit Übergabe von Smarty-Objekt an Ausgabefilter |
|
|
Hallo,
ich habe ein Problem mit dem Ausgabefilter. Ich probiere das Objekt von Smarty, welches eine Eigenschaft der Klasse View ist, als Parameter in die Methode filter zu übergeben.
$this->obj_smarty ist als Parameter in der Methode jedoch nicht erlaubt.
Hat jemand eine Idee?
(Auszug aus Code...)
Code: |
final class view {
public $obj_smarty = null;
...
public function init() {
...
$this->obj_smarty = new Smarty();
...
$this->obj_smarty->register_outputfilter("filter");
$this->obj_smarty->display('index.tpl');
...
}
...
public function filter($str_content, ???????) {
$str_content = preg_replace('~[\r\n\t]+~', '', $str_content);
return $str_content = preg_replace('~[ ]{2,}~', ' ', $str_content);
}
...
}
|
Hier der Code aus dem HowTo...
Code: |
<?php
// fügen Sie folgende Zeilen in Ihre Applikation ein
function protect_email($tpl_output, &$smarty)
{
$tpl_output = preg_replace('!(\S+)@([a-zA-Z0-9\.\-]+\.([a-zA-Z]{2,3}|[0-9]{1,3}))!',
'$1%40$2', $tpl_output);
return $tpl_output;
}
// Ausgabefilter registrieren
$smarty->register_outputfilter("protect_email");
$smarty->display("index.tpl");
// von nun an erhalten alle ausgegebenen e-mail Adressen einen
// einfach Schutz vor Spambots.
?>
|
|
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon May 06, 2013 5:49 pm Post subject: |
|
|
Da in Deinem Beispiel "filter" eine Methode der Klasse View ist muß der Callback in register_outputfilter anders lauten.
Code: | final class view {
public $obj_smarty = null;
...
public function init() {
...
$this->obj_smarty = new Smarty();
...
$this->obj_smarty->register_outputfilter(array($this,"filter"));
$this->obj_smarty->display('index.tpl');
...
}
...
public function filter($str_content, $smarty) {
$str_content = preg_replace('~[\r\n\t]+~', '', $str_content);
return $str_content = preg_replace('~[ ]{2,}~', ' ', $str_content);
}
...
}
|
Smarty übergibt immer sein Object (nicht das von View) als 2. Parameter |
|
Back to top |
|
andre85 Smarty n00b
Joined: 06 May 2013 Posts: 2
|
Posted: Tue May 07, 2013 11:02 am Post subject: |
|
|
Vielen Dank erstmal, doch leider gibt mir Smarty wieder nichts aus. Sehr seltsam. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed May 08, 2013 7:44 pm Post subject: |
|
|
Erhälst Du ne PHP Fehlermeldung oder einfach ne leere Ausgabe?.
Baue doch mal ein var_dump($str_content) oder ein echo... in filter ein zum debuggen was passiert. |
|
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
|