deck john
deck john

Reputation: 647

a link pass multiple parameter in zend framework

hi i am new in zend framework 2.2.0. i want to create the a link that go to delete page right now i am passing only id in the url so i want to pass another id in it.

<a href="<?php echo $this->url('message',array('action'=>'delete', 'id' => $message->message_id));?>">Add to Trash</a>

right now in this link message id is passing i also want to pass one more id named "did" in this link

<a href="<?php echo $this->url('message',array('action'=>'delete', 'id' => $message->message_id,'did'=>$message->deliver_id));?>">Add to Trash</a>

how can i get this ? thanks in advance

Upvotes: 0

Views: 2370

Answers (2)

Mohsen Reza
Mohsen Reza

Reputation: 101

You have to add "did" to your message route like this:

'router' => array(
    'routes' => array(
        'message' => array(
            'type' => 'segment',
            'options' => array(
                'route' => '/:action/:id[/:did]',
                'constraints' => array(
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]+',
                    'id'     => '[0-9]+',
                    'did'    => '[0-9]+',
                ),
                'defaults' => array(
                    'controller' => 'Application\Controller\Index',
                ),
            ),
        ),
    ),
),

echo $this->url('message',array('action'=>'delete', 'id' => $message->message_id,'did'=>$message->deliver_id);
// output: /delete/1/2

Upvotes: 0

edigu
edigu

Reputation: 10099

You should use url view helper's third argument ($options) to pass your variables in the query string. Example:

$route = 'message';
$param = array('action' => 'delete');
$opts  = array(
           'query' => array(
              'id'  => $message->message_id,
              'did' => $message->deliver_id
              )
           );

$this->url($route, $params, $opts);

Upvotes: 1

Related Questions