ezhttp
Summary
Returns GET, POST, session and cookie variables.
Usage
ezhttp( name [, type [, check_existence ] ] )
Parameters
| Name | Type | Description | Required |
|---|---|---|---|
| name | string | The HTTP variable that should be fetched. | Yes. |
| type | string | Source of variable. Default is is HTTP POST. | No. |
| check_existence | mixed | If the specified directive should be checked for existence. | No. |
Returns
Variable value
Description
This operator makes it possible to inspect the contents of HTTP variables (POST, GET, session and cookie variables). The "type" parameter can be used to specify which type of variable that should be extracted. The following options are available:
- post (POST variable)
- get (GET variable)
- session (session variable)
- cookie (cookie variable)
The "check_existence" parameter can be set to TRUE or the string "hasVariable" in order to check if a directive is actually set. In this case, the operator will return either TRUE or FALSE. Note that using the "ezhttp_hasvariable" operator is a better option.
Examples
Example 1
{ezhttp( 'search' )}Returns the "search" POST variable.
Example 2
{ezhttp( 'image', 'get' )}Returns the "image" GET variable.
Example 3
{ezhttp( 'user_id', 'session' )}Returns the "user_id" session variable.
Example 4
ezhttp( 'is_logged_in', 'cookie' )
Returns the 'is_logged_in' cookie variable.
Contributors
- Balazs Halasy Maintainer
- Geir Arne Waaler Updated Maintainer
- Bertrand Dunogier Commenter
- James Robertson Commenter
- patrick kaiser Commenter
- VaL Commenter
- Vids Commenter
- muro Commenter
- Alimi Nabil Commenter
- vytis Commenter
- André Rømcke
- Tobias V. Commenter
- Pike Commenter
Comments (11 historical)
Written by readers of the earlier documentation sites, kept as they were.
Warnings
Bertrand Dunogier ·
It's a little too bad there's no way to avoid a warning when the variable we're fetching is not set ...
Re: Warnings
James Robertson ·
You only recieve a warning? I get see an error. Most annoying!
Re: Re: Warnings
Patrick Kaiser ·
using 3.7.4 and getting an error as well. even testing for the existence fo a get/post var throws an error:
{if ezhttp( 'myvar', 'get' ) } => returns false, but throws error
the same with {if is_set( ezhttp( 'myvar', 'get' ) )}
its a bug in my opinion..
Re: Warnings
VaL ·
you can use in 3.9 (trunk) like:
ezhttp_hasvariable( 'getVar','get' )
or
ezhttp( 'getVar','get','hasVariable' )
Re: Re: Warnings
Vids ·
Yap this works perfectly! I'm not getting error anymore!
Thanks
Re: Re: Warnings
muro ·
Hi I use in 4.3
I'm troubling use ezhttp_hasvariable( 'getVar','get' )
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{set $search_text = ezhttp( 'searchtext' ,'get' ,'hasVariable')}
<form>
<input id="searchtext" name="searchtext" type="text" value="{$search_text|wash}" size="35" />
</form>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
set 'input tag value' as '1'
I hope , set 'input tag value' as '$searchtext'
if i use ezhttp( 'getVar','get' )
set 'input tag value' as '$searchtext'
Why not ?
Alimi Nabil ·
It would be nice if the ezhttp operator could return all vars in the array specified. ezhttp(GET) would return all $_GET vars for example.
ezhttp is not working if caching is turned on.
vytis ·
i put
{set-block scope=root variable=cache_ttl}0{/set-block}
to all templates, because in other way ezhttp will return the same value...
Re: ezhttp is not working if caching is turned on.
André R. ·
Or YOU should rethink your code instead of disable all cache, and recommend others to do so as well..
If you use view parameters ('my.domain.com/my/url/(parameter)/value') instead of GET parameters, then the cache system will store different cached pages depending on the parameters. So that would be:
* Better performance (cache is still on)
* Nicer looking URL
* Better indexable URL
Re: Re: ezhttp is not working if caching is turned on.
Tobias V. ·
Actually, the cache system unfortunately does not store different cached pages, but returns the first requested version after cache cleaning for each parameter combination. Maybe this has something to do with the overall broken cache system in 3.10, but it does not work as expected and documented here.
or null
Pike ·
Returns:
Variable value or null
test for non-existence using
{if not(ezhttp('test'))}
or
{if ezhttp('test')|null()}