Page 1 of 1

Help using decorator plugin

Posted: Fri May 09, 2008 5:26 pm
by joe558
Hi,

I have been using the decorator plugin for some time now without any issues with the exact code from the docs. Now though I am trying to do something slightly different and not having any luck. The only change I've made to the original code is that I need the mysql table name to be a variable instead of hard coded. For example:

Code: Select all

//Extend the replacements class
    class Replacements extends Swift_Plugin_Decorator_Replacements {
        function getReplacementsFor($address) {
            $query = "select col1 as `{col1}`, col2 as `{col2}`, col3 as `{col3l}` from $mydbtable where lead_email = '" . mysql_real_escape_string($address) . "'";
            $result5 = mysql_query($query);
            if (mysql_num_rows($result5) > 0)
            {
                return mysql_fetch_assoc($result5);
            }
        }
    }
When I try to do this I get an error of undefined variable $mydbtable. Is there anyway to pass this into the function from my script?

Thanks,
Joe

Re: Help using decorator plugin

Posted: Sat May 10, 2008 3:00 am
by Chris Corbyn

Code: Select all

class Replacements extends Swift_Plugin_Decorator_Replacements {
        var $table;
        function Replacements($table) {
          $this->table = $table;
        }
        
        function getReplacementsFor($address) {
            $query = "select col1 as `{col1}`, col2 as `{col2}`, col3 as `{col3l}` from " .
            mysql_real_escape_string($this->table) . " where lead_email = '" .
            mysql_real_escape_string($address) . "'";
            $result5 = mysql_query($query);
            if (mysql_num_rows($result5) > 0)
            {
                return mysql_fetch_assoc($result5);
            }
        }
    }
Then when you instantiate it just do "new Replacements('tableName');".

Re: Help using decorator plugin

Posted: Sat May 10, 2008 12:27 pm
by joe558
Thanks Chris!

That worked perfect.

Joe