-- [email protected] <[email protected]> wrote
(on Monday, 23 February 2009, 07:16 AM +0000):
> Hi all,
> Is there any way to tell if an url parameter is present, even when it has no
> value? Something like paramExists()?

If you're within an action controller, yes, there's an easy way:

    if ($this->_hasParam($name)) {
        // found!
    }

Another easy way is to pass the second parameter to getParam(), which is
used for providing a default value; you can then test for the default
value:

    if (!$request->getParam('foo', false)) {
        // not found
    }

This latter is somewhat problematic, as you could potentially have a
false value passed. On the other hand, a null value can never be passed,
and you can test for that:

    if (null === $request->getParam('foo')) {
        // not found
    }

> Consider this example:
> http://www.example.com/newsletter/subscribe/
> controller: newsletter
> action: subscribe
> 
> http://www.example.com/newsletter/subscribe/verify
> controller: newsletter
> action: subscribe
> verify: null
> 
> $request->getParam( 'verify' ); // null, as expected
> $request->paramExists( 'verify' ); // true
> Thank you for any pointers. If you suggestions on how to do this another way,
> without having to set a value of create a route, I'ld love to hear it too.
> Cheers
> 
> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
> Twee keer zo leuk. Deel foto's terwijl je chat met de nieuwe Messenger

-- 
Matthew Weier O'Phinney
Software Architect       | [email protected]
Zend Framework           | http://framework.zend.com/

Reply via email to