Just tried. Doesn't work.
Added:
static function staticFunction() {
return 'it works';
}
Apple
<% control getApples %>
$_color // prints red and green
$staticFunction // nothing
<% end_control %>
Is this a bug?
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
Just tried. Doesn't work.
Added:
static function staticFunction() {
return 'it works';
}
Apple
<% control getApples %>
$_color // prints red and green
$staticFunction // nothing
<% end_control %>
Is this a bug?
Try this:
class Apple {
public static $_color;
function getColor()
{
return self::$_color;
}
function setColor($c)
{
self::$_color = $c;
}
}
class Test_Controller extends Controller {
function init() {
parent::init();
}
function Apples() {
$a = array();
Apple::setColor('red');
$a[] = array('Color'=>Apple::getColor());
Apple::setColor('green');
$a[] = array('Color'=>Apple::getColor());
return new DataObjectSet(new ArrayData($a));
}
}
Edit: Actually I dont think you should name your controller function getApples either renamed to Apples
<% if Apples %>
<% control Apples %>
$Color
<% end_control %>
<% end_if %>
Well, yes, that should work. But it defeats the purpose of object-oriented programming, no?