Below is the code for your controller in which I am return the phtml in JSON. It can we used for AJAX:
use Zend\View\Model\ViewModel; use Zend\View\Model\JsonModel; use Zend\View\Renderer\PhpRenderer; use Zend\View\Resolver; public function searchClientAction() { $renderer = new PhpRenderer(); $map = new Resolver\TemplateMapResolver(array( 'client_search' => __DIR__ . '/../../../view/Client/Client/prepareHTML.phtml', )); $resolver = new Resolver\TemplateMapResolver($map); $renderer->setResolver($resolver); $view = new ViewModel(array( 'message' => 'Hello world', )); $view->setTemplate('client_search'); $result = new JsonModel(array( 'client_name' => $renderer->render($view), 'success' => true, )); return $result; }Update module.config.php:
'view_manager' => array( . . . 'strategies' => array( 'ViewJsonStrategy', ),
No comments:
Post a Comment