1

コントローラ内で次のコードを想定します。

$this->view->addScriptPath('dir1/views/scripts');
$this->view->addScriptPath('dir2/views/scripts');
$this->render('index.phtml');

dir1 / views / scriptsに2つのファイルが含まれている場合:

-index.phtml  
-table.phtml

そして、dir2 / views / scripts:

-table.phtml

これで、dir 2にはindex.phtmlがないため、dir1にindex.phtmlがレンダリングされます。

Index.phtmlは次のようになります。

<somehtml>
       <?= $this->render('table.phtml') ?>
</somehtml>

これが私にとって混乱が始まるところです。スクリプトパススタックに追加された最後のディレクトリにあるtable.phtmlをレンダリングすることを期待しますが、そうではありません。
私の問題に対する簡単な解決策/説明はありますか?

4

3 に答える 3

1

パスはLIFOの順序で使用されているようです。

ソースファイルを見viewRedndererview、どのように機能するかを確認してください。

于 2010-02-11T09:37:45.787 に答える
0

あなたは使用することができます

> $this->view->setBasePath("../application/dir1/views");

それはより具体的です

于 2010-06-13T09:16:38.020 に答える
0

最終的にZend_Viewを拡張し、renderParent関数を追加しました。

class My_View extends Zend_View
{
    private $_file = null;

    private $_name = null;

    /**
     * Finds a view script from the available directories.
     *
     * @param $name string The base name of the script.
     * @return void
     */
    protected function _script($name)
    {
        $this->_file = parent::_script($name);
        $this->_name = $name;

        return $this->_file;
    }

    /**
     * Renders the parent script by looping through all the script paths.
     *
     * @return void
     */
    public function renderParent()
    {
        $scriptPaths = $this->getScriptPaths();

        $found = false;
        for ($i = 0; $i < count($scriptPaths); $i++) {
            if ($this->_file == $scriptPaths[$i] . $this->_name) {
                $found = true;
            } elseif ($found) {
                if (is_readable($scriptPaths[$i] . $this->_name)) {
                    return $this->_run($scriptPaths[$i] . $this->_name);
                }
            }
        }
    }
}
于 2011-06-27T12:39:19.790 に答える