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 » Question about the use of a function in a control block
Our old forums are still available as a read-only archive.
|
Page:
1
|
Go to End | |
| Author | Topic: Question about the use of a function in a control block | 431 Views |
-
Question about the use of a function in a control block

5 September 2008 at 6:14am Last edited: 5 September 2008 6:16am
Suppose I have the following function (in Page.php):
function showMensSweaters() {
$whereStatement = "MenCat = 1 AND SweaterCat = 1";
return DataObject::get("Page", $whereStatement);
}When I call it in a template with a control block, like so (simplified html for readability):
<% control showMensSweaters %>
<a href="$Link" title="View style {$MenuTitle.XML}">$Photo.SetWidth(108)</a>
<% control Styles %>
<p>$StyleNumber</p>
<% end_control %><% end_control %>
it all works. The pages for which the booleans MenCat and SweaterCat are true, are iterated over and rendered. Also, the "Styles" block is included for those pages where a Style is "attached" with a many-many relationship. All is good.
But if I change the whole thing in such a way, that one of the variables for the function is not a boolean but, say, of the text type, like so (and of course change all the associated code accordingly, in how the variables are set in the CMS etc.):
function showMensSweaters() {
$whereStatement = "MenCat = 1 AND SweaterCat = bigsweater";
return DataObject::get("Page", $whereStatement);
}the thing blows up: the template doesn't render at all. What do I have to do to make that kind of thing work?
Thanks in advance!
(edit: added correct 'code' tags)
-
Re: Question about the use of a function in a control block

5 September 2008 at 7:41am
The string needs quotes around it, otherwise the database does a field comparison instead of a string comparison.
function showMensSweaters() {
$whereStatement = "MenCat = 1 AND SweaterCat = 'bigsweater'";
return DataObject::get("Page", $whereStatement);
}
| 431 Views | ||
|
Page:
1
|
Go to Top |
Currently Online: JoshuaLewis, NickJacobs, _Vince
Welcome to our latest member: marcusl


