21288 Posts in 5733 Topics by 2602 members
| Go to End | ||
| Author | Topic: | 1579 Views |
-
Re: Method Calls from Templates Fail

15 January 2010 at 2:57pm
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?
-
Re: Method Calls from Templates Fail

15 January 2010 at 3:06pm Last edited: 15 January 2010 3:16pm
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 %> -
Re: Method Calls from Templates Fail

15 January 2010 at 3:36pm
Well, yes, that should work. But it defeats the purpose of object-oriented programming, no?
| 1579 Views | ||
| Go to Top |


