1

I'm getting into trouble with passing param by url in Zend Framework 2. For example : I want to access page by a URL like this: http://example.com/student/details/aaa it's working, but if my url like this : http://example.com/student/details/1 it's not working, And i still get a 404.

I tried to follow the instruction from how to pass params using a route in Zend Framework 2?

But it still doesn't work.

here's my module.config.php

'student' => array(
                'type'    => 'segment',
                'options' => array(
                    'route'    => '/student[/:action][/:id]',
                    'constraints' => array(
                            'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'id'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                    ),
                    'defaults' => array(
                            '__NAMESPACE__' => 'AppFeeder\Controller',
                            'controller'    => 'Student',
                            'action'        => 'index',
                    ),
                ),
            ),

And i use this $this->getEvent()->getRouteMatch()->getParam('id') in my controller.

Can anyone help me ?

1 Answer 1

2

You are using wrong route rule for id which says start from alphabet then alphabet+number+"_-".

 'id'     => '[a-zA-Z][a-zA-Z0-9_-]*',

Instead you need to change the rule that says start from alphabet+number then alphabet+number+"_-"

 'id'     => '[a-zA-Z0-9][a-zA-Z0-9_-]*',
Sign up to request clarification or add additional context in comments.

1 Comment

Do you have any clue how to pass two variables in url zend?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.