user5542093
user5542093

Reputation:

view output of module in another module in zend framework

i have 2 module 1-login module 2-Application module i want to view MyLoginModule/view/MyLoginModule/index/index.phtml(in this file i have login form) in the my home page i create my home page with Application module i want to view my login form in MyLoginModule in this file:module\Application\view\application\index\index.phtml

or

i have contact-us module i want to view module\contact-us\view\contact-us\index\index.phtml in my main page

my main page create with Application module

thanx in advance

Upvotes: 3

Views: 128

Answers (1)

user5542093
user5542093

Reputation:

i solve it

The code 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);
    }
}

The statement in module.config.php in Login module

'view_helpers' => array(
        'invokables' => array(
            'loginForm' => 'Login\View\Helper\LoginForm'
        )
    ),

Use in view of the application module

<?php

   echo $this->loginForm();
?>

is correct

Upvotes: 1

Related Questions