Login | Forgot password | Register
What is OpenID?
OpenID is an Internet-wide identity system that allows you to sign in to many websites with a single account.
With OpenID, your ID becomes a URL (e.g. http://username.myopenid.com/). You can get a free OpenID for example from myopenid.com.
For more information visit the official OpenID site.
Archive
SilverStripe Forums » Archive » Templating: how to access $REQUEST variables?
Our old forums are still available as a read-only archive.
|
Page:
1
|
Go to End | |
| Author | Topic: Templating: how to access $REQUEST variables? | 744 Views |
-
Templating: how to access $REQUEST variables?

24 April 2008 at 5:49pm
Hi,
i building my first silverstripe portal and stuck at the question how to access $REQUEST variables(like $_GET, $_POST, $_SESSION) in templates? lets say, smarty has reserved variable $smarty in witch i can access these vars. I tried do functions in SS to retrieve these vars, like
function listGET() {
return $_GET;
}
In the template $listGET.foo show the value of $_GET['foo'] var, but how then it use in if statments? <% if a = listGET.foo %> returns a parse error about unexpected "}" at template.
Any help please. -
Re: Templating: how to access $REQUEST variables?

24 April 2008 at 6:31pm
I dont know if this is the proper way to do it but if I need to access a GET var or anything I just create a method and have that return my varible. for example function PageID { return $_GET['PageID']; } (ive removed all the issets/ and checking for the sake of this. And then in the template you can use $PageID to access that GET var. <% 2 = $PageID %>
-
Re: Templating: how to access $REQUEST variables?

24 April 2008 at 8:44pm
The way is proper if you have some variable you must get in template, but lets say we have a filter form with a lot of select fields which has option loaded from control(DB), so how then check which option is selected in filter when we displaying its results? Now im using a basic function which adds and extra field in object from db:
function selectedControl(&$object, $selected, $var) {
if(empty($selected)) return;
foreach ($object as $item)
if($item->$var == $selected) $item->Selected = " selected=\"selected\"";
}but in this way we have two loops(foreach and control, in big amount of data, this will be slowly) and this way isnt very comfortable.
So the question would be - has SSViewer ability to parse array or object in if statment? -
Re: Templating: how to access $REQUEST variables?

25 April 2008 at 2:41pm
The reason that you're finding this a little difficult is that we don't really encourage this style of development with SilverStripe. You should keep your logic in your Controller or DataObject layers, and use the templates to describe how the HTML and CSS should be put together.
-
Re: Templating: how to access $REQUEST variables?

25 April 2008 at 7:55pm
yeah, its true, and after hard work yesterday i understood how to prepare objects in this way, the trouble was, that until SS i worked with commercial CMS with coded source, so all objects were prepared for template from core and then the smarty was very good in this case because it can work with arrays in all ways. now i see templating way it should be. Thanks.
| 744 Views | ||
|
Page:
1
|
Go to Top |
Currently Online: NickJacobs
Welcome to our latest member: marcusl



