Home  >  Article  >  Backend Development  >  大牛们进入解惑

大牛们进入解惑

WBOY
WBOYOriginal
2016-06-13 13:25:11793browse

大牛们进来解惑
比如写个无限导航类

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
array(
    array(
        'id'=>1,
        'pid'=>0,
        'name'=>'主页'
    ),
    array(
        'id'=>2,
        'pid'=>0,
        'name'=>'新闻'
    )



像这样的数据是初始化类的时候存在类属性中还是需要的时候在读取进来(数据库或者文件都行),关键是综合考虑内存效率那种方式比较好
说明:
1、由于是导航,所以会频繁调用
2、此数据会比较的多,树结构大于3,估计在6个的样子


------解决方案--------------------
在需要的时候读进来比较好,速度性能会比较高
http://baike.baidu.com/view/1617569.htm
------解决方案--------------------
探讨
比如写个无限导航类
PHP code

array(
array(
'id'=>1,
'pid'=>0,
'name'=>'主页'
),
array(
'id'=>2,
'pid'=>0,
'name'=>'新闻'
)


------解决方案--------------------
这个导航多数跟目录 和文件有关系,而且以后还要维护什么的,所以数据的对应关系应该通过数据库来存储
然后在需要的时候生成文件再include 这个文件。
------解决方案--------------------
写缓存啊,如果有memcached的话,直接写进去去,要不然文件缓存也可以
------解决方案--------------------
探讨
写入类属性中(初始化就存在),和需要时加载(肯定会被加载,只是应该说比类属性稍微晚点),除了时间上的差别,还有其他啥子差别没有?
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn