2amigos / yii2-usuario

Highly customizable and extensible user management, authentication, and authorization Yii2 extension
https://github.com/2amigos/yii2-usuario
Other
294 stars 142 forks source link

mailer viewPath #431

Closed paskuale75 closed 3 years ago

paskuale75 commented 3 years ago

What steps will reproduce the problem?

How can overwrite mailer views ?

What is the expected result?

What do you get instead?

continue to refer to vendor views.

Here my mailer.php file content:

<?php
return [

    /*
     * --------------------------------------------------------------------------
     * Mailer
     * --------------------------------------------------------------------------
     *
     * Mailer implements a mailer based on SwiftMailer.
     */

    'class' => 'yii\swiftmailer\Mailer',
    //'viewPath' => '@app/mail',
    'transport' => [
        'class' => 'Swift_SmtpTransport',
        'host' => 'smtp.gmail.com',
        'username' => 'xxxxxx@gmail.com',
        'password' => 'xxxxxxx',
        'port' => '587',
        'encryption' => 'tls',
        'streamOptions' => [
            'ssl' => [
                'allow_self_signed' => true,
                'verify_peer'       => false,
                'verify_peer_name'  => false
            ],
        ]
    ],

    /*
     * --------------------------------------------------------------------------
     * useFileTransport property
     * --------------------------------------------------------------------------
     *
     * Send all mails to a file by default. You have to set 'useFileTransport' to
     * false and configure a transport for the mailer to send real emails.
     */

    'useFileTransport' => false,

    /*
     * --------------------------------------------------------------------------
     * viewPath property
     * --------------------------------------------------------------------------
     *
     * Configure the directory that contains the view files for composing emails.
     * Defaults to '@app/mail', let's place its views where it supposed to be.
     */

    'viewPath' => '@app/mail'
];
paskuale75 commented 3 years ago

[SOLVED]

step 1 in module "user" config (in classMap array)


'classMap' => [
        // add this
        'MailService'       => app\modules\myModuleName\services\MailService::class
    ], 

step 2 copy and paste /services/mailService.php file from /vendor to custom module folder and extend it

step 3 In extended file, overwrite $viewPath

class MailService extends baseMailService implements ServiceInterface
{
    protected $viewPath = 'app/modules/myModuleName/views/mail';
}

.... now I can finally customize the views of the emails, placed in the path "/app/modules/myModuleName/views/mail" !

maxxer commented 3 years ago

Can we close this?

paskuale75 commented 3 years ago

Can we close this?

Yes,thanks