如何在CodeIgniter中创建库类的多个实例? [英] How Do You Create Multiple Instances of a Library Class in CodeIgniter?
问题描述
我想在CodeIgniter中创建一个类的几个实例。我已经创建了我的类作为库,但不能弄清楚用于创建多个实例的语法。
CodeIgniter用户指南:
将库指定给不同的对象名称 b
$ b如果第三个(可选)参数是
为空,那么库通常是
分配给与库相同的
名称的对象。例如,如果
库名为Session,它将
分配给一个名为
$ this-> session的变量。
如果你想设置你自己的类
名字,你可以传递它的值到
第三个参数:
$ this-> load-> library('session','',
'my_session');
//现在访问会话类
使用:
$ this-> my_session
我想这就是你要找的。 p>
I'd like to create several instances of a class in CodeIgniter. I have created my class as a library, but cannot figure out the syntax to use to create more than one instance.
From the CodeIgniter users guide:
Assigning a Library to a different object name
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 Session, it will be assigned to a variable named $this->session.
If you prefer to set your own class names you can pass its value to the third parameter: $this->load->library('session', '', 'my_session');
// Session class is now accessed using:
$this->my_session
I think that's what you're looking for.
这篇关于如何在CodeIgniter中创建库类的多个实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!