Re: Re: DataObject with ITX

From: Date: Wed, 16 Apr 2003 01:13:21 +0000
Subject: Re: Re: DataObject with ITX
References: 1 2 3  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-4866@lists.php.net to get a copy of this message
Diego Algorta Casamayou wrote:
Alan Knowles wrote:
Diego Algorta Casamayou wrote:
Does anybody use DataObject AND ITX Templates?
I suspect the $dataObject->toArray() may be usefull for that, (not having used ITX that much) I use it alot now for the quickforms integration code, and usually override toArray and setFrom() to provide a few extra variables, eg. function toArray($s='%s') {
    $ret = parent::toArray($s);
    $ret['prettyDate'] =date('d M Y',$ret['somedate']);
    return $ret;
} I'm not sure if ITX allows you to send arrays when there may not be template elements defined for them. 'more a case of best match', rather than 'fixed matching', perhaps the ITX authors could comment. Regards Alan
Thank you Alan! $dataObject->toArray() is perfect for ITX. Now, I have a problem. I have this code: $tpl = new HTML_Template_ITX('./templates'); $tpl->loadTemplateFile('clientsPerCountry.tpl.html'); $country = new DataObjects_Country; $client = new DataObjects_Client;
change this to $baseClient = new DataObjects_Client;
// I want all countries $country->find(); while ($country->fetch()) { $tpl->setCurrentBlock('country'); $countryArray = $country->toArray(); $tpl->setVariable($countryArray); $tpl->setCurrentBlock('client'); // I want al clients from this country
      $client = $baseClient->__clone();
or just
      $client = new DataObject_Client;
$client->CouId = $country->CouId; //This is the Country ID $client->find(); while($client->fetch()) {
       $clientArray = $client->toArray();
       $tpl->setVariable($clientArray);
       $tpl->parseCurrentBlock();
} $tpl->parse('country'); } $tpl->show();
you shouldnt try to do multiple queries on the same object - it's very messy.., just use a new instance or clone a 'pre-queried' object. - It's one of the few drawbacks of the approach, but as long as you know about this little gotcha, there's little else to worry about. Regards Alan
My problem is that it works for the first country, but starting on the second country it doesn't find any matching clients. I put debug=3 in config.ini and I see it's adding a where clause for every field using values from the last record of clients on the FIRST country, BUT, with the correct CouId because it's the only one I change on purpose. So, I need a way to "reset" the values of my $client object so it doesn't use them for the next find(). ¿Any suggestions? Bytes DAC
-- Can you help out? Need Consulting Services or Know of a Job? http://www.akbkhome.com

« previous php.pear.general (#4866) next »