Welcome Guest, Not a member yet? Register   Sign In
Module's array config in ENV does not work
#1
Question 
(This post was last modified: 05-12-2020, 03:04 AM by harpreetsb.)

Hi,
I have a module as
Code:
modules\Emails
modules\Emails\Config
modules\Emails\Controllers
modules\Emails
Now in my .env file I have following
Code:
Emails\Config\Email.sendTo = '[email protected]'
Emails\Config\Email.sendTo = Emails\Config\Email.settings.protocol = 'smtp'
Emails\Config\Email.settings.SMTPHost = 'smtp.example.com'
Emails\Config\Email.settings.SMTPPort = '345'
As per documentation  the $settings must be an array, but
PHP Code:
<?php namespace Emails\Config;

use 
CodeIgniter\Config\BaseConfig;

class 
Email extends BaseConfig
{

    public $sendTo// works fine

    public $settings// THIS IS NULL

the variable $settings variable is empty;

I also tried something like
Code:
#-- Email --
Emails\Config\Email.settings = []
Emails\Config\Email.settings.protocol = 'smtp'
Still does not work.
What am I doing wrong here?
Reply
#2

Found the Solution:
Solution is to define your array in config.
PHP Code:
<?php namespace Emails\Config;

use 
CodeIgniter\Config\BaseConfig;

class 
Email extends BaseConfig
{

    public $sendTo;
    
    
public $settings = [
        'protocol' => '',
        'SMTPHost' => '',
        'SMTPPort' => '',
        'SMTPUser' => '',
        'SMTPPass' => '',
        'SMTPCrypto' => '',
        'charset' => 'utf-8',
        'mailType' => 'html',
        'wordWrap' => true,
        'newline' => "\r\n",
        'CRLF' => "\r\n",
    ];

and in .env file you can do
Code:
#-- Email --
Emails\Config\Email.settings.protocol = 'smtp'
Emails\Config\Email.settings.SMTPHost = 'smtp.example.com'
Emails\Config\Email.settings.SMTPPort = '123'
Emails\Config\Email.settings.SMTPUser = 'USER'
Emails\Config\Email.settings.SMTPPass = 'PASSWORD'
Emails\Config\Email.settings.SMTPCrypto = 'ssl'
Emails\Config\Email.sendTo = '[email protected]'

THIS WORKED !!!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB