$this->link v registerHelper()

Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
vtitl
Člen | 29
+
0
-

Ahoj,

v Basepresenteru jsem si definoval nový helper a potřebuji v něm vytvořit odkaz. Jenže jakmile pracuji v nové funkci, nemohu přes $this přistoupit k metodě link. Jak to lze vyřešit?

function beforeRender(){
     $this->template->registerHelper('itemProccessRead', function ($item) {
                    //vynechaný kód

                    $tagAnchor = $this->link('Items:tag', "param"); //problém
                    $item = str_replace($tag, $tagAnchor, $item);

                    return $item;

                });
}

Díky

JakubJarabica
Gold Partner | 184
+
0
-

Ahoj, skús toto:

function beforeRender(){
     $that = $this; // v PHP 5.4 nebude nutne pouzivat docasnu premennu a pojde do USE rovno dat $this
     $this->template->registerHelper('itemProccessRead', function ($item) use ($that) {
                    //vynechaný kód

                    $tagAnchor = $that->link('Items:tag', "param"); //problem solved
                    $item = str_replace($tag, $tagAnchor, $item);

                    return $item;

                });
}
vtitl
Člen | 29
+
0
-

Funguje, jak má. Díky;)