cakephp swiftmailer config
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-开发者_StackOverflow中文版>smtpPort =;
$this->SwiftMailer->smtpUsername = '';
$this->SwiftMailer->smtpPassword = '';
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.
精彩评论