1

I'm getting into trouble with passing paramters by URL in Zend Framework.

For example, I have a Controller like this:

class MyController extends AbstractActionController { public function indexAction() { ... } public function updateAction($id) { ... } } 

I want to access the update page by a URL like this: http://example.com/mycontroller/update/1

So how to pass the value 1 to the controller?

Can anyone help me? Thanks a lot.

BTW, I have changed the default router from

'route' => '/[:controller[/:action]]' 

to

'route' => '/[:controller[/:action[/:id]]]', 

but it still doesn't work. And here's the error message below.

Warning: Missing argument 1 for Module\Controller\MyController::updateAction() call in ...

1 Answer 1

2

I've solved the problem!

You should change the function as following:

public function updateAction() { $paramName = $this->getEvent()->getRouteMatch()->getParam('id'); // Do something with $paramName return array(); } 

There're more methods to get parameters in Zend Framework2: How to access route, post, get etc. parameters in Zend Framework 2

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

1 Comment

Yes, and it seems to be simpler.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.