Skip to main content
Rollback to Revision 7
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

UPDATES

Based on KIKO Softwares comments below, this is my stab at using a setter method for the variable key/values while still allowing to set 1 by 1 or setting all my variables at once still by using an Array!

/**
 * Set Variable name and values one by one or at once with an array
 * @param mixed $var_name  Variable name that will be replaced in the Template OR an Array or key=>values
 * @param string $var_value (Optional) The value for a variable/key if not set using an Array.
 */
public function setVar($var_name, $var_value = ''){

    $numargs = func_num_args();

    try
    {
        // If a key and value are passed in, add it to our $_emailValues Array
        if($numargs > 1){
           if(isset($var_name) && $var_name != '' & isset($var_value) && $var_value != ''){
                $this->_emailValues[$var_name] = $var_value;
           }else{
                throw new Exception('ERROR: Template Variable KEY and VALUE must be a string and not be empty');
           }
        // If only 1 argument passed in, check if it is an Array and if so loop it and add each
        // key/value to $_emailValues Array
        }else{
                if(is_array($var_name)){
                    foreach ($var_name as $key => $value) {
                        $this->_emailValues[$key] = $value;
                    }
                }else{
                    throw new Exception('ERROR: Single arguments must be an ARRAY.  Pass an ARRAY or set a 2nd argument as the value.');
                }
        }
    }
    catch(Exception $e)
    {
        echo $e->getMessage(). ' | FILE: '.$e->getFile(). ' | LINE: '.$e->getLine();
    }
}

setVar() Method USAGE

$emailValues = array(
    'username' => 'My username value here',
    'password' => 'my pass'
);

// Set variable key/values using an ARRAY
$emailHtml->setVar($emailValues);



// Set variable key/values 1 by 1
$emailHtml->setVar('username', 'JasonDavis');
$emailHtml->setVar('password', 'my random password value here');

UPDATES

Based on KIKO Softwares comments below, this is my stab at using a setter method for the variable key/values while still allowing to set 1 by 1 or setting all my variables at once still by using an Array!

/**
 * Set Variable name and values one by one or at once with an array
 * @param mixed $var_name  Variable name that will be replaced in the Template OR an Array or key=>values
 * @param string $var_value (Optional) The value for a variable/key if not set using an Array.
 */
public function setVar($var_name, $var_value = ''){

    $numargs = func_num_args();

    try
    {
        // If a key and value are passed in, add it to our $_emailValues Array
        if($numargs > 1){
           if(isset($var_name) && $var_name != '' & isset($var_value) && $var_value != ''){
                $this->_emailValues[$var_name] = $var_value;
           }else{
                throw new Exception('ERROR: Template Variable KEY and VALUE must be a string and not be empty');
           }
        // If only 1 argument passed in, check if it is an Array and if so loop it and add each
        // key/value to $_emailValues Array
        }else{
                if(is_array($var_name)){
                    foreach ($var_name as $key => $value) {
                        $this->_emailValues[$key] = $value;
                    }
                }else{
                    throw new Exception('ERROR: Single arguments must be an ARRAY.  Pass an ARRAY or set a 2nd argument as the value.');
                }
        }
    }
    catch(Exception $e)
    {
        echo $e->getMessage(). ' | FILE: '.$e->getFile(). ' | LINE: '.$e->getLine();
    }
}

setVar() Method USAGE

$emailValues = array(
    'username' => 'My username value here',
    'password' => 'my pass'
);

// Set variable key/values using an ARRAY
$emailHtml->setVar($emailValues);



// Set variable key/values 1 by 1
$emailHtml->setVar('username', 'JasonDavis');
$emailHtml->setVar('password', 'my random password value here');
added 785 characters in body
Source Link
JasonDavis
  • 375
  • 5
  • 16
/**
 * Set Variable name and values one by one or at once with an array
 * @param mixed $var_name  Variable name that will be replaced in the Template OR an Array or key=>values
 * @param string $var_value (Optional) The value for a variable/key if not set using an Array.
 */
public function setVar($var_name, $var_value = ''){

    $numargs = func_num_args();

    try
    {
        // If a key and value are passed in, add it to our $_emailValues Array
        if($numargs > 1){
           if(isset($var_name) && $var_name != '' & isset($var_value) && $var_value != ''){
                $this->_emailValues[$var_name] = $var_value;
           }else{
                throw new Exception('ERROR: Template Variable KEY and VALUE must be a string and not be empty');
           }
        // If only 1 argument passed in, check if it is an Array and if so loop it and add each
        // key/value to $_emailValues Array
        }else{
                if(is_array($var_name)){
                    foreach ($var_name as $key => $value) {
                        $this->_emailValues[$key] = $value;
                    }
                }else{
                    throw new Exception('ERROR: Single arguments must be an ARRAY.  Pass an ARRAY or set a 2nd argument as the value.');
                }
        }
    }
    catch(Exception $e)
    {
        echo $e->getMessage(). ' | FILE: '.$e->getFile(). ' | LINE: '.$e->getLine();
    }
}
/**
 * Set Variable name and values one by one or at once with an array
 * @param mixed $var_name  Variable name that will be replaced in the Template OR an Array or key=>values
 * @param string $var_value (Optional) The value for a variable/key if not set using an Array.
 */
public function setVar($var_name, $var_value = ''){

    $numargs = func_num_args();

    if($numargs > 1){
       if(isset($var_name) && $var_name != '' & isset($var_value) && $var_value != ''){
            $this->_emailValues[$var_name] = $var_value;
       }
    }else{
        if(is_array($var_name)){
            foreach ($var_name as $key => $value) {
                $this->_emailValues[$key] = $value;
            }
        }
    }
}
/**
 * Set Variable name and values one by one or at once with an array
 * @param mixed $var_name  Variable name that will be replaced in the Template OR an Array or key=>values
 * @param string $var_value (Optional) The value for a variable/key if not set using an Array.
 */
public function setVar($var_name, $var_value = ''){

    $numargs = func_num_args();

    try
    {
        // If a key and value are passed in, add it to our $_emailValues Array
        if($numargs > 1){
           if(isset($var_name) && $var_name != '' & isset($var_value) && $var_value != ''){
                $this->_emailValues[$var_name] = $var_value;
           }else{
                throw new Exception('ERROR: Template Variable KEY and VALUE must be a string and not be empty');
           }
        // If only 1 argument passed in, check if it is an Array and if so loop it and add each
        // key/value to $_emailValues Array
        }else{
                if(is_array($var_name)){
                    foreach ($var_name as $key => $value) {
                        $this->_emailValues[$key] = $value;
                    }
                }else{
                    throw new Exception('ERROR: Single arguments must be an ARRAY.  Pass an ARRAY or set a 2nd argument as the value.');
                }
        }
    }
    catch(Exception $e)
    {
        echo $e->getMessage(). ' | FILE: '.$e->getFile(). ' | LINE: '.$e->getLine();
    }
}
added 422 characters in body
Source Link
JasonDavis
  • 375
  • 5
  • 16

setVar() Method USAGE

$emailValues = array(
    'username' => 'My username value here',
    'password' => 'my pass'
);

// Set variable key/values using an ARRAY
$emailHtml->setVar($emailValues);



// Set variable key/values 1 by 1
$emailHtml->setVar('username', 'JasonDavis');
$emailHtml->setVar('password', 'my random password value here');

setVar() Method USAGE

$emailValues = array(
    'username' => 'My username value here',
    'password' => 'my pass'
);

// Set variable key/values using an ARRAY
$emailHtml->setVar($emailValues);



// Set variable key/values 1 by 1
$emailHtml->setVar('username', 'JasonDavis');
$emailHtml->setVar('password', 'my random password value here');
added 1063 characters in body
Source Link
JasonDavis
  • 375
  • 5
  • 16
Loading
edited tags
Link
200_success
  • 145.7k
  • 22
  • 192
  • 481
Loading
deleted 96 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238
Loading
added 688 characters in body
Source Link
JasonDavis
  • 375
  • 5
  • 16
Loading
added 733 characters in body
Source Link
JasonDavis
  • 375
  • 5
  • 16
Loading
deleted 3 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238
Loading
added 733 characters in body
Source Link
JasonDavis
  • 375
  • 5
  • 16
Loading
Source Link
JasonDavis
  • 375
  • 5
  • 16
Loading