21294 Posts in 5734 Topics by 2602 members
| Go to End | Next > | |
| Author | Topic: | 1073 Views |
-
Function doesn't give an output

16 March 2011 at 5:04am Last edited: 16 March 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?
-
Re: Function doesn't give an output

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.
-
Re: Function doesn't give an output

16 March 2011 at 8:54pm Last edited: 16 March 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 -
Re: Function doesn't give an output

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?
-
Re: Function doesn't give an output

17 March 2011 at 12:57am Last edited: 17 March 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?
-
Re: Function doesn't give an output

17 March 2011 at 1:42am Last edited: 17 March 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?
-
Re: Function doesn't give an output

21 March 2011 at 9:26pm
Is your <% control Awtvaluta %> nested within some other control?
| 1073 Views | ||
| Go to Top | Next > |



