CakePHP 2.x
下記はViewのbeforeRenderで何かしたい場合の例。 イベント発生前にハンドラを追加すればいいので、beforeRender()でなくても可。 getEventManager()->attach(array($this, 'beforeRenderView'), 'View.beforeRender', array()); } /** * @param CakeEvent $…
Controllerのrender()をオーバーライドする。 全体のHTMLに対してやるならこれが一番かなと。下記は全角英数字を半角に一括変換する例。 public function render($view = null, $layout = null) { $response = parent::render($view, $layout); $content = $…
テンプレートファイルで $this-> から自前Helperのコード補完を使えるようにする。Eclipseプロジェクト配下の適当な場所に下記の内容でファイルを作成する。 クラス外での補完全部に反映されてしまうが、テンプレート以外で$this->を書くことは基本無いので…
https://github.com/primeminister/cake-master-slave-setup こちらをCakePHP 2.xに対応させたものです。 ついでに色々いじったのでオリジナルとは使い方が違います。app/Model/Datasource/Database/MysqlMasterSlave.php
foreach (Cache::configured() as $config) { Cache::clear(false, $config); } exit;
下記をapp/Model/AppModel.phpに追加。 public function unbindModelExcept($params, $reset = true) { $unbind = array(); $assocs = $this->associations(); foreach ($assocs as $assoc) { if (in_array($assoc, $params, true)) { continue; } foreach (…