Help using decorator plugin

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
joe558
Forum Newbie
Posts: 6
Joined: Mon Feb 04, 2008 5:44 pm

Help using decorator plugin

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Help using decorator plugin

Post 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');".
joe558
Forum Newbie
Posts: 6
Joined: Mon Feb 04, 2008 5:44 pm

Re: Help using decorator plugin

Post by joe558 »

Thanks Chris!

That worked perfect.

Joe
Post Reply