includePaths.library = APPLICATION_PATH“/../library”
并在myproject根目录中创建库目录
类Zend_View_Helper_TabEntry扩展Zend_View_Helper_Abstract {
公共函数TabEntry(){
}
}
类Zend_View_Helper_TabEntries扩展Zend_View_Helper_TabEntry {
公共函数TabEntries(){
}
}
答案 0 :(得分:2)
根据ZF编码应用程序结构,正确的版本将是:
在application.ini中:
resources.view.helperPath.Your_View_Helper = "Your/View/Helper"
然后帮助者:(不知道为什么你需要另一个抽象类):
// library/Your/View/Helper/TabEntry/Abstract.php
class Your_View_Helper_TabEntry_Abstract extends Zend_View_Helper_Abstract {
public function tabEntry($param1, $param2) {} // note the lower case here
}
// library/Your/View/Helper/TabEntries.php
class Your_View_Helper_TabEntries extends Your_View_Helper_TabEntry_Abstract {
public function tabEntries($param1, $param2) {...} // note the lower case
}
在视图中:
$this->tabEntries();
重要提示:call_user_func
和Linux文件系统区分大小写。
答案 1 :(得分:0)
仔细检查引导程序中的代码
在Bootstrap.php中我添加了一些代码:
$view->addHelperPath('MyView/Helpers', "library_MyView_Helpers"); $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer'); $viewRenderer->setView($view);
应该更像
$view->addHelperPath('My/View/Helpers', "My_View_Helpers");
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
$viewRenderer->setView($view);
在我这边,我使用:
// Add path to project view helpers
Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->initView();
Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view
->addHelperPath('Julien/View/Helper', 'Julien_View_Helper')
;
并在Julien/View/Helper/Percent.php
<?php
class Julien_View_Helper_Percent extends Zend_View_Helper_Abstract {
public function percent ( $percentage ) {
return $percentage * 100 . '%';
}
}
然后在视图中调用
<?= $this->percent(0.255) ?>
将输出
25.5%
我的目录布局如下
project/
lib/
Julien/
View/
Helper/
Percent.php
Zend/
modules/
public/
.htaccess
index.php
答案 2 :(得分:0)
Zend框架/位于/var/www/html/you
1)you/application/views/helpers/<Magic is here>
2)将名为“Stuff.php”的文件放在上面的路径
中<?php class Zend_View_Helper_Stuff extends Zend_View_Helper_Abstract { public function stuff() { $output = "IK BEN View Helper en DAN????"; return htmlspecialchars($output); } } ?>
3)转到/ application / views / scripts / index / index.phtml
<?= $this->stuff(); ?>
:)
4)输出将是$ output。
答案 3 :(得分:0)
在zend 3中添加帮助器
在module / Admin / src / View / Helper / Helper.php中创建辅助类Helper.php
之后添加以下代码:
<?php
namespace Admin\View\Helper;
use Zend\View\Helper\AbstractHelper;
class Helper extends AbstractHelper {
public function test($messages) {
echo $messages;
}
}
module / Admin(您的模块名称)/config/module.config.php
使用Zend \ ServiceManager \ Factory \ InvokableFactory;
'view_helpers' =>[
'factories' => [
View\Helper\Helper::class => InvokableFactory::class,
],
'aliases' => [
'mainHelper' => View\Helper\Helper::class
],
],
调用视图
<?php
$this->mainHelper()->test('Abhishek');
?>