1

currently the adminEmail is set in the params.php file. I am trying to change the 'adminEmail' dynamically and then I can assign the email value I want. There is the code in the params.php.

return array(
    // this is displayed in the header section
    'title' => 'title here',
    // this is admin email
    'adminEmail' => 'admin@email.com',

But the admin emails can be more than one(eg. admin1@email.com, admin2@email.com), how can I set admin email dynamically in params.php ?

Thanks in advance!

Louise
  • 23
  • 5

2 Answers2

0

You can try set multiple emails on adminEmail, and at runtime access it using index. E.G

//asign multiple email ids to adminEmail as array
'params'=>array(
    // this is used in contact page
    'adminEmail'=>array('webmaster@example.com','sany@gmail.com','xxx@yahoo.com','webmaster2@example.com')
),

//access it using array index at runtime as your requirement
<?php echo Yii::app()->params['adminEmail'][1];?>  //sany@gmail.com
<?php echo Yii::app()->params['adminEmail'][2];?>  // xxx@yahoo.com

OR

Create a static method on a class that will generate dynamic email ids and then set it to your adminEmail param .e.g

class Email
      {
    public static function generateEmailIds()
    {
      //or any other way to generate email ids or id
              return array('webmaster@example.com',
              'sany@gmail.com',
              'xxx@yahoo.com');
    }
}
'params'=>array(
    // this is used in contact page
    'adminEmail'=>Email::generateEmailIds(),
)
A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103
0

Well, although I don't recommend this approach, what you want to do can be done like this:

  • You need to store your array in a file in serialized form (that is, call function serialize() on it. That will turn the array into a string.

  • You can read the file and unserialize it (that is, call function unserialize() on it. That will turn the string that you read form file back into a PHP array.)

    $handle = fopen('path/to/file','rb');
    $contents = fread($handle,999).
    $array = unserialize($contents);
    
  • set 'adminEmail' to what you want it to be:

    $array['adminEmail'] = 'new@email.com; 
    

    or even

    $array['adminEmail']= array(..lots of emails..);
    
  • then you need to turn the array into a string and write the array back to file. Like this, for example:

    $serialized_contents = serialize($array);
    fwrite($handle, $serialized_contents);
    

There may be more efficient ways to do this if you want to.

Community
  • 1
  • 1
Felipe
  • 11,557
  • 7
  • 56
  • 103