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 with register_function using class method

 
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 -> General
View previous topic :: View next topic  
Author Message
marcos_cct
Smarty n00b


Joined: 17 Dec 2005
Posts: 1

PostPosted: Mon Dec 19, 2005 1:18 am    Post subject: Problem with register_function using class method Reply with quote

Hello, guys. I'm having a problem when I try to use register_function() inside a class.

I'm going to simplify the source code, just leaving the important parts.

Firstly, I have the following class Portal:

Code:
abstract class Portal{

   static function do_formataStr($params) {
      $params["c"] = (empty($params["c"])) ? "" : $params["c"];
         for ( $x = 0; $x < strlen($params["s"]); $x++ ) {
            $o = ($params["n"]+$x >= strlen($params["s"]) ?
               $params["s"] :    ($params["s"]{$params["n"]+$x} == " " ?
               substr($params["s"],0,$params["n"]+$x) . $params["c"] : ""));
            if ( $o != "" ) {
               return $o;
            }
         }
   }

}


I have a class named Loader that extends Portal, and a subclass LoaderMaster that extends Loader.
In LoaderMaster I have to register do_formataStr, defined in Portal.
Here's the code:
Code:

require_once(GeralB_Loader."loader.php");

class LoaderMaster extends Loader {

   function LoaderMaster($pagina, $usuario, $template, $db) {
      $this->construir($pagina, $usuario, $template, $db); //defined in Loader
   }

   function monta() {
         $this->cacheControl(); //also defined in Loader
         $this->mostraCab();
   }

   function mostraCab(){
      $this->template->register_function('cortaSrt', array('Portal','do_formataStr'));
      $this->template->display('cabecalho.tpl');
   }

}


As you can see, the class Loader has a parameter $template, which is a Smarty instance.

Unfortunately, I got this message:

Fatal error: Call to undefined function: do_formatastr() in /home/safonso/public_html/website/smarty/master/templates_c/%%82^829^829E2AC2%%cabecalho.tpl.php on line 51

Here's the problem: if I copy the whole function do_formataStr to a line below $this->template->register_function('cortaSrt', array('Portal','do_formataStr')), all the code works perfectly. But I don't want to do this every time I call register_function. That'd be quite stupid.

In cabecalho.tpl I wrote:

Code:
{cortaSrt s=$usuario.Nome n="15" c=""}


I tried to set cache_attrs = false, but it was useless.


Hope you guys can help me. I'm stuck in it for three days, and I still can't find a proper solution. Thanks!
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 -> General 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