Custom configuration files - Codeigniter

I am trying to create my custom email configuration file that includes my mail server configuration.

I created it in the / config directory and the code below:

<?php $config = Array( 'protocol' => 'smtp', 'smtp_host' => 'ssl://smtp.googlemail.com', 'smtp_port' => 465, 'smtp_user' => ' mertmetinbjk@gmail.com ', 'smtp_pass' => '*************', 'mailtype' => 'html' ); $this->load->library('email', $config); $this->email->set_newline("\r\n"); ?> 

and to use it, I call in my kayit.php, which is the controller constructor

  $this->config->load('email'); 

However, I get this error enter image description here

+4
source share
7 answers

I quote from the manual:

If you prefer not to set preferences using the above method, you can instead put them in a configuration file. Just create a new file called email.php, add $ config array to this file. Then save the file in config / email.php

The configuration file is just AN ARRAY (named $ config), and only because it does not have access to $ this reference. The code you use (for example, loading the library) must not be inside the controller, not inside the configuration file!

+6
source

You need to create a file called email.php in the ./application/config/ folder and create an array with your values ​​in this file. In your case, it should be

 $config = Array( 'protocol' => 'smtp', 'smtp_host' => 'ssl://smtp.googlemail.com', 'smtp_port' => 465, 'smtp_user' => ' mertmetinbjk@gmail.com ', 'smtp_pass' => '*************', 'mailtype' => 'html' ); 

Now, when you load the email library into the application, it overrides the default configuration with this. Remember that the name of the array must be a config.

+4
source

Since this configuration file is for the built-in email class , it will be automatically loaded if it is called config/email.php .

If you prefer not to set preferences using the above method, you can instead put them in a configuration file. Just create a new file called email.php , add $config array to this file. Then save the file to config/email.php and it will be used automatically. You will not need to use the $this->email->initialize() function if you save your preferences in the configuration file.

You cannot (why should you) call $this->load inside the configuration file.

In addition, you cannot declare such configuration files. $config = Array( , you overwrite all other values ​​in $config . You need to declare each option separately.

 $config['protocol'] = 'smtp'; $config['smtp_host'] = 'ssl://smtp.googlemail.com'; $config['smtp_port'] = 465; $config['smtp_user'] = ' mertmetinbjk@gmail.com '; $config['smtp_pass'] = '*************'; $config['mailtype']= 'html'; 
+4
source

You cannot create methods in the configuration file because it did not load the CodeIgniter instance.

+1
source

Look Codeignitor userGuide http://codeigniter.com/user_guide/libraries/email.html

 $config['protocol'] = 'sendmail'; $config['mailpath'] = '/usr/sbin/sendmail'; $config['charset'] = 'iso-8859-1'; $config['wordwrap'] = TRUE; $this->email->initialize($config); $this->load->library('email'); $this->email->from(' your@example.com ', 'Your Name'); $this->email->to(' someone@example.com '); $this->email->cc(' another@another-example.com '); $this->email->bcc(' them@their-example.com '); $this->email->subject('Email Test'); $this->email->message('Testing the email class.'); $this->email->send(); echo $this->email->print_debugger(); 
+1
source

in your configuration /config/email.php :

 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); $config = Array( 'protocol' => 'smtp', 'smtp_host' => 'ssl://smtp.googlemail.com', 'smtp_port' => 465, 'smtp_user' => ' mertmetinbjk@gmail.com ', 'smtp_pass' => '*************', 'mailtype' => 'html' ); 

in your controller:

 $this->config->load('email'); var_dump((array)$this->config); //show all the configs including those in the email.php 
+1
source

first you can delete the email.php file in config / email.php . after checking the code.

0
source

Source: https://habr.com/ru/post/1398817/


All Articles