Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter load library and call with alias name

I wonder if I can use an alias name after call a library, let say:

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

How I can do this?

like image 762
Nere Avatar asked Oct 28 '15 16:10

Nere


2 Answers

You can do that by providing a third parameter while loading your library.

If the third (optional) parameter is blank, the library will usually be assigned to an object with the same name as the library. For example, if the library is named 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 at the Loader Class documentation of Codeigniter.

like image 198
sotoz Avatar answered Oct 14 '22 22:10

sotoz


The only way I thing might be close to the way that your after is if you load the library as

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

And then

$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);

Or

$this->load->library('email', NULL, 'em');
// Email config stuff here.
$this->em->from();
$this->em->to();
$this->em->subject();
$this->em->message();
like image 21
Mr. ED Avatar answered Oct 14 '22 23:10

Mr. ED