Business Logic Code

In order to send mail from application, I use EMailer Extension.

The extension worked great and every thing was great.

But, I started ask me about, where I place the code to setup smtp parameter? Should I repeat the code every time that I have to send mail?

My first thought was write an action to abstract this code, but I have to send mails from others controllers. On the other hand, I wrote a new model, is this correct?

Please, let me know your opinion about,

Thank you in advance,

Well, what keeps you from registering said extension as an application component? That way you would only have to set up your smtp parameters once.

Thank you for your response,

I don’t know the way to setup smtp parameters in the application component.

I read the Emailer documentation, but I didn’t find this.

On the other hand, where is the correct place to locate logical code like this?

That’s interesting because it’s documented on the exact same page you’ve linked to :lol: Putting this into your config should do:












After having done so, you can access the mailer extension via [font="Courier New"]Yii::app()->mailer->…[/font]

In general, Yii favours fat model opposed to fat controller (i.e. store all the business logic in your models). If you need to share logic between different models, try to write a behavior.

Thank you again for your response,

I made changes in my code to setup EMailer extension into main.php file. Everything works well.

On the other hand, I read the information about Behaviors and Models.

When I have to create a business logic model and this model is not related with a table directly, Do I have to create a model inherits from CFormModel?

Yes :)

Not exactly in fact - you must extend CModel, but CFormModel will give some additional nice features to use with web forms.