Download custom Yii component

I am trying to use a custom class that I created to send mail so that I can store controller files in thin. I created my own class and put it in the components folder. Then I added:

'sendMail' => array( 'class'=>'application.components.SendMail.', ), 

under the main components of my main configuration file.

This should allow me to access the class directly right? I am trying to use:

 Yii::app()->SendMail->MailerConfirmation(); 

and

 Yii:app()->MailerConfirmation(); 

and all that I have is errors.

Can someone tell me how I enable a custom component? Maybe I'm doing it all wrong?

+7
source share
2 answers

First it should be:

 'sendMail' => array( 'class'=>'application.components.SendMail', ), 

Note the absence of a dot at the end of "SendMail" instead of "SendMail". In addition, this configuration expects that you have the php file SendMail.php, in the protected / components directory, which is a class called "SendMail" and that this component extends CApplicationComponent. The component identifier will have the lower first letter, for example Yii::app()->sendMail , and this will return an instance of the SendMail class. I do not know what MailerConfirmation is, but if it is a method of the SendMail object, you should access it, like Yii::app()->sendMail->MailerConfirmation()

If this does not help, send the code and post the errors you get.

+12
source

Please note that if you are not going to set any properties of the component in the configuration file or use other CApplicationComponent functions, and your configuration file includes by default:

 'import'=>array( 'application.models.*', 'application.components.*', ), 

You can put your SendMail.php class in the component directory and it will automatically load by calling it via:

 $mailer = new SendMail(); 

then call your methods with:

 $mailer->MailerConfirmation(); 

if you want to use CApplicationComponent , you may need here or here for a few examples, as well as Yii tutorials.

+2
source

All Articles