コントローラーの特定のアクションに基づいてユーザーに表示されるナビゲーションメニューがあります。これが私がやっていることです。
//in each controller-action where i want "action navigation menu"
public function indexAction()
{
$this->_helper->navigation()->renderActionNavigation();
}
public function newAction()
{
$this->_helper->navigation()->renderActionNavigation();
}
それに応じてナビゲーションメニューが表示されます。これが私の navigation.xml ファイルです。
<?xml version="1.0" encoding="UTF-8"?>
<configdata>
<item-index>
<new-item>
<label>New Item</label>
<route>admin-item-new</route>
</new-item>
<delete-item>
<label>Delete Item</label>
<uri>#</uri>
</delete-item>
</item-index>
<item-new>
<publish-unpublish-item>
<label>Save & Close</label>
<uri>#</uri>
</publish-unpublish-item>
<delete-item>
<label>Save & New</label>
<uri>#</uri>
</delete-item>
</item-new>
</configdata>
各ナビゲーション メニューの親要素は、たとえば上記の navigation.xml ファイルの命名規則を表します。
`<item-index>` represents item{controller}index{action}
`<item-new>` represents item{controller}new{action}
//and so on
これがアクションヘルパーです。私が使用しているNavigation.php
class Zend_Controller_Action_Helper_Navigation extends Zend_Controller_Action_Helper_Abstract
{
private $_view = null;
public function direct()
{
$this->_view = Zend_Layout::getMvcInstance()->getView();
$this->_view->placeholder('action-navigation');
return $this;
}
public function renderActionNavigation()
{
$config = new Zend_Config_Xml(
APPLICATION_PATH.'/configs/navigation.xml', strtolower(
$this->getRequest()->getControllerName().'-'.
$this->getRequest()->getActionName()
)
);
$container = new Zend_Navigation($config);
$this->_view->partial('partials/_action-navigation.phtml', array('container' => $container));
}
}
そして最後に_action-navigation.phtml
<?php $this->placeholder('action-navigation')->captureStart(); ?>
<div class="statsRow">
<div class="wrapper" >
<?php foreach($this->container as $page): ?>
<a href="<?php echo $page->getHref(); ?>" class="<?php echo $page->class; ?>" id="<?php echo $page->id; ?>"></a>
<?php endforeach; ?>
</div>
</div>
<?php $this->placeholder('action-navigation')->captureEnd(); ?>
私のディレクトリ構造は次のとおりです
/application
/layouts
admin.phtml
default.phtml
/modules
/admin
/controllers
/helpers
/Navigation.php
IndexController.php
/views
/helpers
/scripts
/partials
_action-navigation.pthml
sidebar.phtml
/index
/item
私が経験している奇妙な行動はです。私の Bootstrap.php ファイルには、空の _initView() メソッドがあります。このメソッドが存在する場合、私のアプリケーションは正しく動作します。このメソッドは空であることに注意してください。しかし、それを削除すると、次のエラーが表示されます。
Application error
Exception information:
Message: script 'partials/_action-navigation.phtml' not found in path (./views/scripts/)
Zend Framework によるこの動作を理解できません。アクション ナビゲーション コードは、Bootstrap の _initView メソッドにどのように関連していますか? 何が起こっているのか、これに対する修正またはコードの改善に関する提案はありますか?
更新: 問題はこのコード行にあります
$this->_view->partial('partials/_action-navigation.phtml', array('container' => $container));