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've moved the forum!

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.

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   2474 Views

Avatar
quanto

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) %>
           <img>$Filename</img>
        <% 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?

Avatar
Willr

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.

Avatar
quanto

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

Avatar
quanto

Community Member, 91 Posts

16 March 2011 at 9:46pm

Ok i'm a bit further:

<?xml version="1.0" encoding="utf-8" ?>
<pagina>
  <% control Children %>
  <bouwnummer$Nummer>
    <boven>
      
        <% control getDir(1) %>
           <img> $Filename</img>
        <% end_control %>
      <tekstalg><![CDATA[ $BovenShort ]]></tekstalg>
      <bouwsoort>$BovenSoort</bouwsoort>
      <prijs>$BovenPrijs</prijs>
      <type>$BovenType</type>
      <verkocht>$BovenVerkocht</verkocht>
      <bouwnummer_sub>$BovenNummer</bouwnummer_sub>

    </boven> 
    <beneden>
      <tekstalg><![CDATA[ $BenedenShort ]]></tekstalg>
      <bouwsoort>$BenedenSoort</bouwsoort>
      <prijs>$BenedenPrijs</prijs>
      <type>$BenedenType</type>
      <verkocht>$BenedenVerkocht</verkocht>
      <bouwnummer_sub>$BenedenNummer</bouwnummer_sub>
    </beneden>
  </bouwnummer$Nummer>
  <% end_control %>
  
</pagina>

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

Avatar
martimiz

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?

Avatar
tdmarko

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'));
preg_match_all('/\<Currency\>(.+)\<\/Currency\>/sU',$xml_file,$wic_priceavail);
$artikul = 'EUR';
preg_match_all('/\<Currency\>(.+)\<ID\>'.$artikul.'<\/ID\>(.+)\<\/Currency\>/sU',$xml_file,$show_info);
preg_match_all('/\<Units\>(.+)\<\/Units\>/sU',$show_info[2][0],$units);
preg_match_all('/\<Rate\>(.+)\<\/Rate\>/sU',$show_info[2][0],$rate);

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?

Avatar
tdmarko

Community Member, 4 Posts

21 March 2011 at 9:05pm

Guys, any ideas?

Avatar
martimiz

Forum Moderator, 1391 Posts

21 March 2011 at 9:26pm

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

Go to Top