在Phalcon中初始化有两个方法:initialize()和onConstruct()。这两个方法有什么不同呢?
先来看看歪果仁的回答吧,虽然我看不大懂:
Phalcon offers two ways for controller initialization, thy are theinitializeandonContructmethods.
The basic difference between these two methods is thatinitializeis called only when a controller is created by the framework to proceed with the execution of an action.
Since you instantiating a controller objectad-hoc,initializewill not be called, only onConstruct will.
我的理解:
initialize()是Phalcon框架创建这个Controller的时候初始化的,不同于__construct()。
onConstruct()则是类初始化,等同于__construct()。
So,总结一下:
在Phalcon中对框架的初始化操作放在initialize()中;
对于Controller的初始化要放在onConstruct()中。
注:随意一写,订正留言。
网友评论