Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Problem mit Übergabe von Smarty-Objekt an Ausgabefilter

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
andre85
Smarty n00b


Joined: 06 May 2013
Posts: 2

PostPosted: Mon May 06, 2013 1:44 pm    Post subject: Problem mit Übergabe von Smarty-Objekt an Ausgabefilter Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon May 06, 2013 5:49 pm    Post subject: Reply with quote

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
View user's profile Send private message
andre85
Smarty n00b


Joined: 06 May 2013
Posts: 2

PostPosted: Tue May 07, 2013 11:02 am    Post subject: Reply with quote

Vielen Dank erstmal, doch leider gibt mir Smarty wieder nichts aus. Sehr seltsam.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Wed May 08, 2013 7:44 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP