• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Module's array config in ENV does not work

#1
Question 
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.