如何在CodeIgniter中创建库类的多个实例? [英] How Do You Create Multiple Instances of a Library Class in CodeIgniter?

查看:145
本文介绍了如何在CodeIgniter中创建库类的多个实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在CodeIgniter中创建一个类的几个实例。我已经创建了我的类作为库,但不能弄清楚用于创建多个实例的语法。

解决方案

CodeIgniter用户指南:



CI用户指南:装载程序类


将库指定给不同的对象名称 b
$ b

如果第三个(可选)参数是
为空,那么库通常是
分配给与库相同的
名称的对象。例如,如果
库名为Session,它将
分配给一个名为
$ this-> session的变量。



如果你想设置你自己的类
名字,你可以传递它的值到
第三个参数:
$ this-> load-> library('session','',
'my_session');



//现在访问会话类
使用:



$ this-> my_session


我想这就是你要找的。

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:

CI Users Guide: Loader Class

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆