Codeigniter加载库并使用别名调用

Ner*_*ere 6 php codeigniter

我想知道在调用库后是否可以使用别名,让我们说:

$this->load->library('email','em');
Run Code Online (Sandbox Code Playgroud)

我怎么能这样做?

sot*_*toz 11

您可以通过在加载库时提供第三个参数来实现.

如果第三个(可选)参数为空,则通常会将库分配给与库名称相同的对象.例如,如果库名为Calendar,则会将其分配给名为$ this-> calendar的变量.

如果您更喜欢设置自己的类名,可以将其值传递给第三个参数:

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

// Calendar class is now accessed using:
$this->my_calendar
Run Code Online (Sandbox Code Playgroud)

阅读Loader Class Codeigniter文档中的更多内容.