在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框架創(chuàng)建這個Controller的時候初始化的帚湘,不同于__construct()。
onConstruct()則是類初始化巩螃,等同于__construct()演怎。
So,總結(jié)一下:
在Phalcon中對框架的初始化操作放在initialize()中避乏;
對于Controller的初始化要放在onConstruct()中爷耀。
注:隨意一寫,訂正留言淑际。