Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Function doesn't give an output

Go to End

10 Posts   1465 Views


16 March 2011 at 5:04am (Last edited: 16 March 2011 5:05am), Community Member, 81 Posts

I'm trying to get the next function into my (XML) output:

class HousePage_Controller extends Page_Controller {
function init() {

function getDir($id){
$doSet = new DataObjectSet();

$sqlQuery = new SQLQuery();
$sqlQuery->select = array('Filename');
$sqlQuery->from = array('File');
$sqlQuery->where = array('Filename LIKE \'%type%\' AND `ClassName` = \'Image\'');
$val = $sqlQuery->execute();

foreach($val as $value){
$record = array('Filename' => $value['Filename']);
$doSet->push(new ArrayData($record));
return $doSet;

The (XML) template looks like this:

<% if getDir(1) %>
<% control getDir(1) %>
<% end_control %>
<% end_if %>

It looks like a normal query to me, but I don't get any output. Even not when I change the query or just try to shout something form the function into the output.
When I try ?showqueries the query doesn't show up.

Does anyone have an idea?


16 March 2011 at 5:55pm Forum Moderator, 5511 Posts

Is the PHP getting into that function at all? You can check using a die('123') at the top of it and seeing if 123 appears. Make sure you have ?flush=all to clear the template cache.

All init() functions need to include a parent::init() class FYI.


16 March 2011 at 8:54pm (Last edited: 16 March 2011 9:19pm), Community Member, 81 Posts

No it's even not getting into the php function at all :(.
I've putted parent::init() into the function init(), but it doesn't give any results.

Also I tried to put a test function like

function testasdf(){
return "test";

but it didn't gave an output also


16 March 2011 at 9:46pm Community Member, 81 Posts

Ok i'm a bit further:

<?xml version="1.0" encoding="utf-8" ?>
<% control Children %>

<% control getDir(1) %>
<img> $Filename</img>
<% end_control %>
<tekstalg><![CDATA[ $BovenShort ]]></tekstalg>

<tekstalg><![CDATA[ $BenedenShort ]]></tekstalg>
<% end_control %>


The issue is that the second control is not used. When i'm putting it outside the first control, it works. What's wrong?


17 March 2011 at 12:57am (Last edited: 17 March 2011 1:00am), Forum Moderator, 1091 Posts

It might be like this:

Within your <% control Children %> you do not have access to any methods within the HousePage_Controller class, because the control structure returns the childpages as a bunch of DataObjects. So you do have access to their HousePage class (the DataObject in this case) and any of its methods

I suppose you could try moving/copying your getDir() method to the HousePage class like it is, as it seems not to depend on any properties/methods in the Controller...

Although... I don't really understand what you are doing in <img> $Filename </img> ??? That doesn't seem to create valid HTML?


17 March 2011 at 1:42am (Last edited: 17 March 2011 1:43am), Community Member, 4 Posts

Hi there!

I'm having the same problem here trying to integrate custom PHP with XML.

I have this function in mysite/code folder:

class Valuta extends Page {}

class Valuta_Controller extends Page_Controller {

function Awtvaluta() {

$xml_file = file_get_contents('http://www.***/vk/xml.xml?date='.date('Ymd'));
$artikul = 'EUR';

print $artikul;
print $units[1][0];
print $rate[1][0];


And the controller in the template:

<% control Awtvaluta %>
<% end_control %>

Tried inserting die into function, seems like it doesen't see it at all.

What I'm doing wrong?


21 March 2011 at 9:05pm Community Member, 4 Posts

Guys, any ideas?


21 March 2011 at 9:26pm Forum Moderator, 1091 Posts

Is your <% control Awtvaluta %> nested within some other control?

Go to Top