在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()中。
注:隨意一寫,訂正留言。