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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

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

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

Function doesn't give an output

Go to End

10 Posts   2135 Views


Community Member, 91 Posts

16 March 2011 at 5:04am

Edited: 16/03/2011 5:05am

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?


Forum Moderator, 5523 Posts

16 March 2011 at 5:55pm

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.


Community Member, 91 Posts

16 March 2011 at 8:54pm

Edited: 16/03/2011 9:19pm

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


Community Member, 91 Posts

16 March 2011 at 9:46pm

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?


Forum Moderator, 1391 Posts

17 March 2011 at 12:57am

Edited: 17/03/2011 1:00am

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?


Community Member, 4 Posts

17 March 2011 at 1:42am

Edited: 17/03/2011 1:43am

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?


Community Member, 4 Posts

21 March 2011 at 9:05pm

Guys, any ideas?


Forum Moderator, 1391 Posts

21 March 2011 at 9:26pm

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

Go to Top