when to create component and when use helepr?

when to create component and when use helper function?

For example I want to send emails using templates.

I really dont know if the place of this is in the main.php components by creating CApplicationComponent, or just create class and few static functions?

What is the best?

For example I created pack of functions that email with templates etc. using Zend_Mail , dont know if It is right for me to actually create component for this or just use as static methods ::)

This is best practice question

An e-mail sender may have a lot of configurations, like SMTP login details and other parameters that you do not want to write every time you use this feature.

For instance, it is easier to set the SMTP details for sending e-mails in config/main.php and to send e-mails like this:


Than sending an e-mail with this code:


'smtpServer'=>'sample server',



Also, you can misspell something in the configuration and there will appear some hard to find bugs.

Anyway, this is just my opinion.

Vlad V

You dont have to use this:


'smtpServer'=>'sample server',



You can use EmailHelper::send()

And inside params put the email config…

( ‘emailConfig’ => array(…) )

In the background this is what it do

$mail->send( $smtp ? new Zend_Mail_Transport_Smtp(Yii::app()->getParams()->emailConfig['smtp'], Yii::app()->getParams()->emailConfig) : null )

The main reason for this question is - the temptation to use extensions etc. and than your main.php becomes bloated with trillion of components… :D

Maybe sometimes just better to create helper functions?

Actually now I have class named Helper

And inside I have commonly used functions => static methods of Helper.

But just can’t decide maybe some stuff worth to be components… ???

dckurushin, you are right. That is also a solution to do this, but that means that you must add a few new parameters to your application for every helper that requires configuration you add. This can be not-so-handy when the applications grows.

Creating components and configuring them individually may probably save some time when working with big applications.