What does the params mean for router --> assemble?

zend-mvc

#1

Hi, about the zf3 component router,

    $response = $e->getResponse();
    $router = $e->getRouter();
    $url = $router->assemble(array('controller'=>'orders','action'=>'outmeasure'),array('name'=>'application'));
    $response->getHeaders()->addHeaderLine('Location', $url);
    $response->setStatusCode(302);
    $e->stopPropagation(true);
    return $response;

I am not sure about which kind of params I can pass to the methond assemble. I read the official document as https://docs.zendframework.com/zend-router/routing/, it just said like:

    interface RouteInterface
    {
        public static function factory(array $options = []);
        public function match(Request $request);
        public function assemble(array $params = [], array $options = []);
    }

It is hard for me to figure out what params and options I should pass to.

Any one who knew it clear pls tell me, thank you!


#2

These are parameters you create yourself when defining a route, eg.

'route' => '/orders/:order_id'

So one of parameters could be value of fund_code to generate a URL for it:

$url = $router->assemble(array('controller'=>'orders','action'=>'outmeasure', 'order_id' => 1),array('name'=>'application'));

#3

@Alexander_Romanenko
Thanks for your reply!

So, the first input params is the constraints area variables? like controller, action, and id as defined as follow:

                'orders' => [
                    'type' => Segment::class,
                    'options' => [
                        'route' => '/orders[/:action[/:id]]',
                        'constraints' => [
                            'action' => '[a-zA-Z][a-zA-Z0-9_-]*[a-zA-Z0-9]',
                            'id' => '[0-9]+',
                        ],
                        'defaults' => [
                            'controller' => Controller\OrdersController::class,
                            'action' => 'websiteorder',
                        ],
                    ],
                ], 

and the second input param is the router name like ‘appliction/orders’?

Pls confirm, it is important to me. Thank you again!


#4

That is correct.

Also correct.


#5

@Alexander_Romanenko

Thank you so much!