Ian Warner
Ian Warner

Reputation: 1068

Zend Framework Routing - passing hidden params

I want to pass additional params through the URL helper and router - that therefore will not appear in the address bar - but are accessible via the getParam call

My route is below - notice the tagID I want to be passed invisibly though

        'router' => array(
        'routes' => array(
            'tag' => array(
                'route' => '/tag/:tag',
                'defaults' => array(
                    'module' => 'default',
                    'controller' => 'tags',
                    'action' => 'profile',
                    'tag'   => '',
                    'tagID' => ''
                )
            )
        )

The URL helper specifies the TagID

url(array('tag' => $tag, 'tagID' => $v->id), 'tag', true) ?>

Basically is this possible to then get the address bar to show

localhost.com/tag/php

but the controller to have access to the tag and tagID params?

Cheers

Ian

Upvotes: 0

Views: 1453

Answers (3)

ApeOnFire
ApeOnFire

Reputation: 659

This isn't possible as far as I know. There's nowhere to hide any variables because you're dealing with a standard GET request. This is really about the http protocol, not Zend.

There are two ways of moving data/state between urls: GET (i.e. Encoded into the actual URL and POST.

As a POST request isn't appropriate here you're unfortunately stuck with visible URL parameters, or reconstructing the tagID from the tag name on the receiving page.

Upvotes: 1

KomarSerjio
KomarSerjio

Reputation: 2911

In your action use:
$tagId = $this->_getParam('tagId', 'yourDefaultValue');

Upvotes: 0

Niklas
Niklas

Reputation: 30002

If you add a route for each tag, you can assign defaults for them and you won't need to explicitly define them in the url.

Like this (foreach tag):

        'route' => '/tag/php',
        'defaults' => array(
            'module' => 'default',
            'controller' => 'tags',
            'action' => 'profile',
            'tag'   => 'php',
            'tagID' => 'phpID'
        )

Upvotes: 1

Related Questions