symfony 1.4 + Propel の DBレプリケーションで任意のタイミングでマスタ接続に切り替える
データ更新後はマスタに接続する
app.yml
all: propel: force_master_flashes: [notice]
frontendConfiguration.class.php
<?php public function configure() { $this->dispatcher->connect('context.load_factories', array($this, 'loadFactoriesEvent')); } public function loadFactoriesEvent(sfEvent $event) { $user = $event->getSubject()->getUser(); foreach (sfConfig::get('app_propel_force_master_flashes') as $name) { if ($user->hasFlash($name)) { Propel::setForceMasterConnection(true); break; } } }
特定のアクションでは常にマスタに接続する
app.yml
all: propel: force_master_actions: - [module, action]
frontendConfiguration.class.php
<?php public function configure() { $this->dispatcher->connect('controller.change_action', array($this, 'changeActionEvent')); } public function changeActionEvent(sfEvent $event) { $mod_act = array($event['module'], $event['action']); if (in_array($mod_act, sfConfig::get('app_propel_force_master_actions'))) { Propel::setForceMasterConnection(true); } }