Prasad Patel
Prasad Patel

Reputation: 747

Package installation error in Yii2 framework?

I have a requirement to use PHPOffice/PhpSpreadsheet, to install PhpSpreadsheet I followed this link.

So I installed PhpSpreadsheet into my project using 'composer' by running the command

composer require phpoffice/phpspreadsheet

at command prompt while installing it said that

Using version dev-master for phpoffice/phpspreadsheet

and was installed successfully(FYI check Screenshot), after installing when I tried to login into my application, I am getting a different error as

Cannot redeclare PHPMailerAutoload() 

(previously declared in" for emails I am using 'phpmailer' including the path as

require_once('../vendor/phpmailer/PHPMailerAutoload.php');

as my "PHPMailer" folder resides in 'vendor' folder of Yii2 framework.

By the way I am building my application on Yii2 framework and I am very new to Yii2 framework.

Can anyone please tell, how to fix this? Thanks.

enter image description here

Upvotes: 0

Views: 171

Answers (1)

Chux
Chux

Reputation: 1227

You don't have to use require for packages installed via composer. Yii autoload's feature will take care for that. You just have to write the appropriate use statements in your code. Actually, the mailer is a component declared into the main app, so you don't need the use statement at all

Yii::$app->mailer->compose('/my/mail_view', ['model' => $model])
                ->setFrom([Yii::$app->params['myMail'] => 'My Name'])
                ->setTo($model->email)
                ->setSubject('My subject')
                ->send();

Upvotes: 2

Related Questions