0
Q
如何註冊查看幫助
A
回答
4
我猜你只需要在配置文件中的設置,但我會告訴全路在Zend的3
首先註冊視圖助手,我們需要的視圖助手:
namespace MyNamespace\View\Helper;
use Zend\View\Helper\AbstractHelper;
class TestViewHelper extends AbstractHelper
{
public function __invoke()
{
// your code...
}
}
如果我們需要注入一些依賴關係,然後我們需要創建自定義工廠,但是如果我們的視圖助手不需要其他服務/類,那麼我們可以跳過這一步
namespace MyNamespace\Factory\View\Helper;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use MyNamespace\View\Helper\TestViewHelper;
class TestViewHelperFactory implements FactoryInterface
{
/**
*
* @param ContainerInterface $container
* @param string $requestedName
* @param null|array $options
* @return TestViewHelper
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$class = $requestedName ? $requestedName : TestViewHelper::class;
$auth = $container->get('MyCustomAuth');
$viewHelper = new $class($auth);
return $viewHelper;
}
/**
* Provided for backwards compatibility; proxies to __invoke().
*
* @param ContainerInterface|ServiceLocatorInterface $container
* @return TestViewHelper
*/
public function createService(ServiceLocatorInterface $container)
{
return $this($container, TestViewHelper::class);
}
}
最後一步是註冊我們的視圖助手在module.config.php
'view_helpers' => [
'aliases' => [
'viewPlugin' => View\Helper\TestViewHelper::class,
],
'factories' => [
View\Helper\TestViewHelper::class => InvokableFactory::class // Or use your own factory
]
],
而且......在我們的視圖模板,我們可以這樣使用它:
index.phtml
<?php echo $this->viewPlugin(); ?>
相關問題
- 1. 註冊Apple幫助手冊
- 2. C/C + +註冊表幫助
- 3. SQL查看幫助
- 4. Android查看幫助
- 5. 如何取消註冊Mac應用程序幫助手冊
- 6. 幫助註冊依賴屬性
- 7. 幫助!用戶註冊問題!
- 8. 啓動註冊的mime幫助程序
- 9. django社會化註冊錯誤幫助
- 10. Windsor IoC示例幫助 - 「HttpServiceWatcher&未註冊。」
- 11. Codeigniter幫助用戶註冊腳本
- 12. 幫助報告查看器
- 13. Tkinter幫助查看器
- 14. 當幫助窗口彈出時,如何退出時查看python幫助(os.listdir)
- 15. 注意:未定義的索引:page nothing幫助註冊
- 16. 需要幫助註冊/註冊(OAuth/OpenId與Facebook和雅虎)並登錄
- 17. 如果您在Handlebars.js中預編譯自定義幫助程序,您如何註冊自定義幫助程序?
- 18. ASP.NET mvc RenderAction登錄和註冊查看
- 19. Magento - 法師::註冊表內查看
- 20. android吐司和查看幫助
- 21. Typo3 8.2查看幫助命名空間
- 22. 需要幫助的強類型查看
- 23. Spring Boot和Thymeleaf的查看幫助器
- 24. ZF2查看幫助器配置
- 25. Windows 10 bootmgr幫助:查看源代碼
- 26. IcePDF查看器定製幫助
- 27. Rails heroku幫助kaminari查看錯誤
- 28. Visual Studio 2010中的幫助查看器
- 29. Mysql幫助查看更多按鈕
- 30. SQL注入幫助