I have widget which is calling an action for another controller and I need to pass a parameter to the action. I tried the following so far and I am getting the following error :
Error
Fatal error: Call to a member function getParam() on a non-object in C:\dev\projects\OnlineFieldEvaluation\vendor\zendframework\zendframework\library\Zend\Mvc\Controller\Plugin\Params.php on line 118
Widget
namespace OnlineFieldEvaluation\View\Helper;
use OnlineFieldEvaluation\Controller\TabsController;
use Zend\View\Helper\AbstractHelper;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class IdentityInformationWidget extends AbstractHelper implements ServiceLocatorAwareInterface
{
protected $idinfoService = null;
public function __construct(TabsController $idinfoService)
{
$this->idinfoService = $idinfoService;
}
...
/**
* @param $id
*/
public function __invoke($id)
{
$viewModel = $this->idinfoService->editidentityinformationAction($id);
return $this->getView()->render($viewModel);
}
}
Controller:
public function editidentityinformationAction()
{
$id = (int)$this->params()->fromRoute('id', 0);
//$id = (int)$this->params('id', 0);
...
$view = new ViewModel(array(
'id' => $id,
'form' => $form,
));
$view->setTemplate('online-field-evaluation/tabs/editidentityinformation.phtml');
return $view;
}
Calling from view
<?php echo $this->identityInformationWidget(3); ?>
EDIT 1: after trying : " $id = $this->getEvent()->getRouteMatch()->getParam('id', 0);
"
Event:
and "$this->getEvent()->getRouteMatch()
" returns null
I am trying to modify this example for my use case: http://www.michaelgallego.fr/blog/2012/10/06/how-to-replace-the-action-helper-in-zf-2-and-make-great-widgetized-content/