Codeigniter download library and call with alias

I wonder if I can use an alias after calling the library, say:

$this->load->library('email','em');

How can i do this?

+4
source share
2 answers

This can be done by providing a third parameter when loading the library.

If the third (optional) parameter is empty, the library is usually assigned to an object with the same name as the library. For example, if the library is called Calendar, it will be assigned to a variable named $ this-> calendar.

If you prefer to set your own class names, you can pass its value to the third parameter:

$this->load->library('calendar', NULL, 'my_calendar');

// Calendar class is now accessed using:
$this->my_calendar

Read more in the Loader Class Codeigniter documentation .

+8
source

, , ,

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

$em = new Email();

// All the email config stuff goes here.

$em->from('email', 'Name');
$em->to('email');
$em->subject('Test Email');
$message = 'Some Message To Send';
$em->message($message);

$this->load->library('email', NULL, 'em');
// Email config stuff here.
$this->em->from();
$this->em->to();
$this->em->subject();
$this->em->message();
+3

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


All Articles