0
我真的不想問這個問題,但現在我無法幫助。我想在我的視圖助手中使用路由或重定向控制器插件。我知道視圖助手擴展視圖層的功能,併爲我們的應用程序的可重用性。控制器插件擴展了控制器層的功能。但我想要任何其他解決方案來做到這一點。如何使用在ZF2視圖助手路由
這裏是我的視圖助手:
<?php
namespace Application\View\Helper;
use Zend\View\Helper\AbstractHelper;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class GetSiteSettings extends AbstractHelper implements ServiceLocatorAwareInterface {
protected $serviceLocator;
/**
* Set the service locator.
*
* @param ServiceLocatorInterface $serviceLocator
* @return CustomHelper
*/
public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
$this->serviceLocator = $serviceLocator;
return $this;
}
/**
* Get the service locator.
*
* @return \Zend\ServiceManager\ServiceLocatorInterface
*/
public function getServiceLocator()
{
return $this->serviceLocator;
}
public function __invoke()
{
$redirect = $this->redirect()->toRoute('my_account');
/*$sm = $this->getServiceLocator()->getServiceLocator();
$config = $sm->get('Config');
return $config['site_settings'];*/
}
}
?>
在上面的代碼中,行:
$redirect = $this->redirect()->toRoute('my_account');
真的不工作,我也嘗試了太多的東西,使之完成,但沒有任何幫助。有人知道解決方案嗎?
謝謝。