アプリの起動時に最初に1回だけやる共通処理を作る
それは application/Bootstrap.php のクラス内に記述する。
その際にこのように _init
から始まるメソッドで定義しておくと自動的に実行される。
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { protected function _initHoge() { // 初期化処理 } }
たぶんこれが実装部分だろう
public function getClassResources() { if (null === $this->_classResources) { if (version_compare(PHP_VERSION, '5.2.6') === -1) { $class = new ReflectionObject($this); $classMethods = $class->getMethods(); $methodNames = array(); foreach ($classMethods as $method) { $methodNames[] = $method->getName(); } } else { $methodNames = get_class_methods($this); } $this->_classResources = array(); foreach ($methodNames as $method) { if (5 < strlen($method) && '_init' === substr($method, 0, 5)) { $this->_classResources[strtolower(substr($method, 5))] = $method; } } } return $this->_classResources; }