3

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.