OOPP MemorandaさんとこにあったMojavi, QF連携でのFormLoadFilterについて。
素晴らしいのでやってみました。(via t-kawazu)
<?php
class FormLoadFilter extends Filter{
function execute(&$filterChain, &$controller, &$request, &$user) {
$form_file = BASE_DIR.'modules/'.$controller->getCurrentModule().'/forms/'.$controller->getCurrentAction().'Form.class.php';
if (is_readable( $form_file ) === true) {
require_once($form_file);
$form_name = $controller->getCurrentAction().'Form';
<strong>$form = & new $form_name($controller, $request, $user);</strong>
$request->setAttributeByRef('form', $form);
$filterChain->execute(&$controller, &$request, &$user);
$request->removeAttribute('form');
} else{
$filterChain->execute(&$controller, &$request, &$user);
}
}
}
?>
これって、
<?php
class FormLoadFilter extends Filter{
function execute(&$filterChain, &$controller, &$request, &$user) {
$form_file = BASE_DIR.'modules/'.$controller->getCurrentModule().'/forms/'.$controller->getCurrentAction().'Form.class.php';
if (is_readable( $form_file ) === true) {
require_once($form_file);
$form_name = $controller->getCurrentAction().'Form';
<strong>$instance =& new $form_name();</strong>
<strong>$form =& $instance->execute($controller, $request, $user);</strong>
$request->setAttributeByRef('form', $form);
$filterChain->execute(&$controller, &$request, &$user);
$request->removeAttribute('form');
} else{
$filterChain->execute(&$controller, &$request, &$user);
}
}
}
?>
こうじゃね?
コンストラクタだと$thisに$formを突っ込むしか返しようがなくて少しトリッキー。
ref: FormLoadFilter