我在访问 View 中的自定义 View 助手时遇到问题。在 layout.phtml 中调用 helper 完美运行。
采埃孚版本:1.11.2
应用程序.ini
resources.view[] =
Bootstrap :
protected function _initViewSettings()
{
$this->bootstrap('view');
$view = $this->getResource('view');
$view->doctype('XHTML1_STRICT');
$view->setScriptPath(APPLICATION_PATH . '/views/scripts/');
$view->addHelperPath(APPLICATION_PATH . '/layouts/helpers/', 'Layout_Helper_');
$view->addHelperPath(APPLICATION_PATH . '/views/helpers/', 'View_Helper_');
}
助手:(application/views/helpers/Loader.php)
class View_Helper_Loader extends Zend_View_Helper_Abstract
{
public function loader()
{
$loader_html = '
<div class="loading">
<div class="bullet"></div>
<div class="bullet"></div>
<div class="bullet"></div>
<div class="bullet"></div>
</div>';
return $loader_html;
}
}
查看:
<?php
echo $this->loader();
?>
错误:
Plugin by name 'Loader' was not found in the registry; used paths: Zend_View_Helper_: Zend/View/Helper/
为什么我不能在我的 View 中使用助手?
最佳答案
也许尝试将您的 View 显式添加到 View 渲染器:
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
'ViewRenderer'
);
$viewRenderer->setView($view);
我无法完全重现您的问题 - 让它在布局中起作用,但在 View 中不起作用。
如果我将 View 资源添加到 application.ini,在 ZF 1.11.14 中,一些连接会自动发生,但如果我在 Bootstrap 中创建 View (新 Zend_View)作为资源,我必须显式传递它到 View 渲染器。
关于php - Zend Framework - 从 View 访问 View Helper,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39268766/