在 zend 框架中的另一个模块中查看模块的输出
view output of module in another module in zend framework
我有2个模块
1-登录模块
2-应用模块
我想查看 MyLoginModule/view/MyLoginModule/index/index.phtml(在此文件中我有登录表单)
在我的主页
我用应用程序模块创建我的主页
我想在这个文件的 MyLoginModule 中查看我的登录表单:module\Application\view\application\index\index.phtml
或
我有联系我们的模块,我想查看 module\contact-us\view\contact-us\index\index.phtml
在我的主页
我的主页使用应用程序模块创建
提前致谢
我解决了
代码ViewHelper
namespace Login\View\Helper;
use Zend\View\Helper\AbstractHelper;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\View\Model\ViewModel;
use Login\Form\LoginForm as Formulaire;
class LoginForm extends AbstractHelper implements ServiceLocatorAwareInterface
{
protected $sm;
public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
$this->sm = $serviceLocator;
return $this;
}
public function getServiceLocator()
{
return $this->sm;
}
public function __invoke()
{
$form = new Formulaire();
$layout = new ViewModel(array(
'form' => $form
));
$viewRender = $this->getServiceLocator()->getServiceLocator()->get('ViewRenderer');
$layout->setTemplate('login/index/index.phtml');
return $viewRender->render($layout);
}
}
登录模块module.config.php中的语句
'view_helpers' => array(
'invokables' => array(
'loginForm' => 'Login\View\Helper\LoginForm'
)
),
针对应用模块的使用
<?php
echo $this->loginForm();
?>
正确
我有2个模块 1-登录模块 2-应用模块 我想查看 MyLoginModule/view/MyLoginModule/index/index.phtml(在此文件中我有登录表单) 在我的主页 我用应用程序模块创建我的主页 我想在这个文件的 MyLoginModule 中查看我的登录表单:module\Application\view\application\index\index.phtml
或
我有联系我们的模块,我想查看 module\contact-us\view\contact-us\index\index.phtml 在我的主页
我的主页使用应用程序模块创建
提前致谢
我解决了
代码ViewHelper
namespace Login\View\Helper;
use Zend\View\Helper\AbstractHelper;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\View\Model\ViewModel;
use Login\Form\LoginForm as Formulaire;
class LoginForm extends AbstractHelper implements ServiceLocatorAwareInterface
{
protected $sm;
public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
$this->sm = $serviceLocator;
return $this;
}
public function getServiceLocator()
{
return $this->sm;
}
public function __invoke()
{
$form = new Formulaire();
$layout = new ViewModel(array(
'form' => $form
));
$viewRender = $this->getServiceLocator()->getServiceLocator()->get('ViewRenderer');
$layout->setTemplate('login/index/index.phtml');
return $viewRender->render($layout);
}
}
登录模块module.config.php中的语句
'view_helpers' => array(
'invokables' => array(
'loginForm' => 'Login\View\Helper\LoginForm'
)
),
针对应用模块的使用
<?php
echo $this->loginForm();
?>
正确