Udai kumar
Udai kumar

Reputation: 233

How to set same view file for different actions in zf2

Hello friends I am new in zf2 and unable to call same view file for dynamic action. Basically my url is "http://localhost:8084/g/raj" but the last one is raj that is changing. But I want to call single view file from different module. Just want to change last action but call same view file. I have used this code but it is not working.It redirected to home page.I want to change only view file without changing url.

 $result = new ViewModel();
 $result->setTemplate('Application/IndexController/index');
 return $result;

Please give any reply.Thanks in advance.

Upvotes: 0

Views: 177

Answers (1)

flobrflo
flobrflo

Reputation: 31

In your setTemplate() you have to send path of your template and not the action.

$result = new ViewModel();
$result->setTemplate('path/to/my/view');
return $result;

(you probably search a path like: application/index/index.phtml)

Upvotes: 1

Related Questions