Jump to:

23355 Posts in 17744 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Function doesn't give an output

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

Page: 1 2
Go to End
Author Topic: 1394 Views
  • quanto
    Avatar
    Community Member
    81 Posts

    Function doesn't give an output Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: Function doesn't give an output Link to this post

    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.

  • quanto
    Avatar
    Community Member
    81 Posts

    Re: Function doesn't give an output Link to this post

    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

  • quanto
    Avatar
    Community Member
    81 Posts

    Re: Function doesn't give an output Link to this post

    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?

  • martimiz
    Avatar
    Forum Moderator
    1067 Posts

    Re: Function doesn't give an output Link to this post

    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?

  • tdmarko
    Avatar
    Community Member
    4 Posts

    Re: Function doesn't give an output Link to this post

    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?

  • tdmarko
    Avatar
    Community Member
    4 Posts

    Re: Function doesn't give an output Link to this post

    Guys, any ideas?

  • martimiz
    Avatar
    Forum Moderator
    1067 Posts

    Re: Function doesn't give an output Link to this post

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

    1394 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.