Mój router wygląda tak
'route' => '/:action[/:id]', 'id' => '[0-9]+', 'action' => '[a-zA-Z][a-zA-Z0-9_-]*', ),
public function indexAction() { $action = $this->getEvent()->getRouteMatch()->getParam('action', 'index'); $vm = new ViewModel(); 'action' => $action )); return $vm; }
$this->getEvent()->getRouteMatch()->getParam('id', '0');
$action = $this->getEvent()->getRouteMatch()->getParam('action', 'index');
$action = $this->params()->fromRoute('action', 'index');
namespace Product\Helper; use Zend\View\Helper\AbstractHelper; class Helper extends AbstractHelper { public function __invoke() { return $this->params()->fromRoute('action', 'index'); } }
Fatal error: Call to undefined method Product\Helper\Helper::params() in...
dlaczego ta metoda params nie moze byc uzyta ?
class Params extends AbstractHelper { protected $event; public function __construct($event) { $this->event = $event; } public function __invoke($param = null, $default = null) { if ($param === null) { return $this; } return $this->fromRoute($param, $default); } public function fromRoute($param= null, $default = null) { if($param === null) { return $this->event->getRouteMatch()->getParams(); } return $this->event->getRouteMatch()->getParam($param, $default); } }
class Module { //... //inne ustawienia //... public function getViewHelperConfig() { 'Params' => function ($helper) { $sm = $helper->getServiceLocator(); $app = $sm->get('Application'); return new Params($app->getMvcEvent()); } ), ); } }
<?php $routes = $this->params()->fromRoute('action', 'index'); ?>
<?php $routes = $this->params('action', 'index'); ?>