views:

43

answers:

1

hi i am using swiftmailer component in my app and am looking for a way to have a separate config (perhaps in config folder?) for swiftmailer that checks what debug mode i am using and thus uses different settings?

case 1: on production mode use simple smtp server without auth. case 2: on debug mode use gmail settings or other settings since i am developing locally

is this possible?

the settings code case 1:

$this->SwiftMailer->smtpHost = ''; 

the settings code case 2:

        $this->SwiftMailer->smtpType = ''; 
        $this->SwiftMailer->smtpHost = ''; 
        $this->SwiftMailer->smtpPort =; 
        $this->SwiftMailer->smtpUsername = ''; 
        $this->SwiftMailer->smtpPassword = ''; 
+1  A: 

I think the quickest way would be:

<?php
    Configure::load('swiftmailer');
    $this->SwiftMailer->smtpType =
      Configure::read('SwiftMailer.'.Configure::read().'.smtpType');
    $this->SwiftMailer->smtpHost = 
      Configure::read('SwiftMailer.'.Configure::read().'.smtpHost');
    $this->SwiftMailer->smtpPort = 
      Configure::read('SwiftMailer.'.Configure::read().'.smtpPort');
    $this->SwiftMailer->smtpUsername = 
      Configure::read('SwiftMailer.'.Configure::read().'.smtpUsername');
    $this->SwiftMailer->smtpPassword = 
      Configure::read('SwiftMailer.'.Configure::read().'.smtpPassword');
?>

Now where to put it on. I would suggest the Controller constructor, that way it's nice and tidy. For the values you can always use a private config file:

// /app/config/swiftmailer.php:
<?php
  $config['SwiftMailer'][0]['smtpType'] = 'value';
  $config['SwiftMailer'][0]['smtpHost'] = 'value';
  $config['SwiftMailer'][0]['smtpPort'] = 'value';
  $config['SwiftMailer'][0]['smtpUsername'] = 'value';
  $config['SwiftMailer'][0]['smtpPassword'] = 'value';

  $config['SwiftMailer'][1]['smtpType'] = 'value';
  $config['SwiftMailer'][1]['smtpHost'] = 'value';
  $config['SwiftMailer'][1]['smtpPort'] = 'value';
  $config['SwiftMailer'][1]['smtpUsername'] = 'value';
  $config['SwiftMailer'][1]['smtpPassword'] = 'value';

  $config['SwiftMailer'][2]['smtpType'] = 'value';
  $config['SwiftMailer'][2]['smtpHost'] = 'value';
  $config['SwiftMailer'][2]['smtpPort'] = 'value';
  $config['SwiftMailer'][2]['smtpUsername'] = 'value';
  $config['SwiftMailer'][2]['smtpPassword'] = 'value';
?>

You can find a more generic example on Configuration Class v 1.2 and Configuration Class v 1.3.

They seem to have the same content, so it seems that it hasn't changed from 1.2 to 1.3.

Hope it helps.

Gustavo Carreno
super! waiting :D
Mikelangelo
Oky, completed the example with more specific code and added the links to the CookBook in case you want to investigate further. Cheers
Gustavo Carreno
by the calsas constructor do you mean the "controller/components/swiftmailer.php"? i am using the http://bakery.cakephp.org/articles/view/updated-swiftmailer-4-xx-component-with-attachments-and-plugins
Mikelangelo
Actually yes, you could use the component that you created. It's in userland and not under the cake code so it looks fine to me.
Gustavo Carreno
Ahhhh, but it would also mean that you would have that config for EVERY app sharing the component, so maybe use it on the Controller constructor that calls it? That way it's local to the app only. dunno, your choice.
Gustavo Carreno
perhaps putting this info in a model? whats best practife?
Mikelangelo
Hummm, I don't think. Doesn't really ring a bell with what I know about the "CakeWay".
Gustavo Carreno