LotusPhp笔记之:基于ObjectUtil组件的使用分析
Jun 13, 2016 am 11:52 AM
ObjectUtil组件其实就是单例模式的最好范例,声明调用各个组件的时候,用ObjectUtil调用,可以有效的防止调用过多的类而导致错误或者资源浪费。
比如调用Db组件,这样声明就可以了
$db = LtObjectUtil::singleton('LtDb');
singleton方法是LtObjectUtil类中唯一的方法,目的就是声明类库,如果该类库存在init()方法,然后调用该类库的init()的方法。
ObjectUtil 还有一个快速调用的函数,可以在框架里或者模板里进行快速调用
格式如下:
C('LtDb');
其实就是函数内部调用的LtObjectUtil::singleton('LtDb');
LotusPhp 是不太主张过多的使用静态类的,这个是框架中唯一的静态类。
对于静态类的优劣,不是今天说的主题,不过大家可以看看这篇基于PHP静态类的原罪详解>的文章,就是说静态类的,可以作为参考。

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What software is crystaldiskmark? -How to use crystaldiskmark?

What should I do if the notes I posted on Xiaohongshu are missing? What's the reason why the notes it just sent can't be found?

How to download foobar2000? -How to use foobar2000

How to add product links in notes in Xiaohongshu Tutorial on adding product links in notes in Xiaohongshu

BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange?
