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-&gt;setAttributeByRef('form', $form);
            $filterChain-&gt;execute(&$controller, &$request, &$user);
            $request-&gt;removeAttribute('form');
        } else{
            $filterChain-&gt;execute(&$controller, &$request, &$user);
        }
    }
}
?&gt;

これって、

&lt;?php
class FormLoadFilter extends Filter{
    function execute(&$filterChain, &$controller, &$request, &$user) {
        $form_file = BASE_DIR.'modules/'.$controller-&gt;getCurrentModule().'/forms/'.$controller-&gt;getCurrentAction().'Form.class.php';
        if (is_readable( $form_file ) === true) {
            require_once($form_file);
            $form_name = $controller-&gt;getCurrentAction().'Form';
            <strong>$instance =& new $form_name();</strong>
            <strong>$form =& $instance->execute($controller, $request, $user);</strong>
            $request-&gt;setAttributeByRef('form', $form);
            $filterChain-&gt;execute(&$controller, &$request, &$user);
            $request-&gt;removeAttribute('form');
        } else{
            $filterChain-&gt;execute(&$controller, &$request, &$user);
        }
    }
}
?&gt;

こうじゃね?
コンストラクタだと$thisに$formを突っ込むしか返しようがなくて少しトリッキー。

ref: FormLoadFilter

Comments


Option