Accessing minus parameter in templates
Archived from the Xataface Users forum.
SilverCorvus — Tue Feb 08, 2011 4:23 am
I stumbled over the problem, that I had to access some of the minus parameters (e.g. -action, -table) in templates, but this wasn’t possible the normal way:
- Code: Select all
{if $ENV.REQUEST.-table == ...} -- doesn't work.
You can’t access it, when the key-value of the array (because it’s in fact $ENV[‘REQUEST’][‘-table’]) doesn’t meet the php variable naming conventions. So minus, space, dot ect. doesn’t work.
- Code: Select all
{if $ENV.REQUEST.`with space` == ...} {if $ENV.REQUEST."min-us" == ...} {if $ENV.REQUEST.'with.dot' == ...}
All these scenarios of “bad keys” and tried solutions via escaping don’t work.
There are two possible ways:
- Rewrite the array: Probably not so good for Xataface
- A workaround:
- Code: Select all
{assign var=_table value="-table"} {if $ENV.REQUEST.$_table == ...)
In fact it is a Smarty problem, but because of the naming convention of Xataface I thought posting this could help others who stumble over this problem too.
shannah — Tue Feb 08, 2011 12:59 pm
Yes. This is an annoyance, but there are a few solutions in Xataface.
- Some of the common query parameters have been added directly to the $ENV variable:
- $ENV.action
- $ENV.table
- $ENV.limit
- $ENV.start
- $ENV.mode
- $ENV.search
- The Dataface_Application class which is accessible from the $ENV variable has a getQueryParam method that allows you to get any query parameter. This takes input parameters without the prefixed dash. e.g. to get the value of $_GET[‘-action’], you would call $ENV.APPLICATION_OBJECT->getQueryParam(‘action’)
-Steve
SilverCorvus — Tue Feb 08, 2011 3:19 pm
But these directly added parameters are from the query, as you said. But in my special case I would have needed from the request - look at the array to compare:
- Code: Select all
[REQUEST] => Array ( [-table] => char ) [QUERY] => Array ( [-table] => char [-action] => list [--original_action] => list [-cursor] => 0 [-skip] => 0 [-limit] => 30 [-mode] => list ) [action] => list [table] => char
The query/directly added parameters contain also the default value, not the pure request ones.
But there is also your shown way number 2 to accomplish it, if this very special case occurs.