Re: Trouble with Datagrid, Dataobject and joined tables

From: Date: Thu, 23 Mar 2006 20:59:57 +0000
Subject: Re: Trouble with Datagrid, Dataobject and joined tables
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-23423@lists.php.net to get a copy of this message
On 3/23/06, t.bothorel@free.fr <t.bothorel@free.fr> wrote: > Hi, > > I just want to use Datagrid to display table rows, but I want to replace foreign > keys 'id' field values with the real name from the foreign table. > 'database.links.ini' is set properly. > > Here is what I use to print a table with only two columns, the title of an > article and the auhor name from the author table: > > -------- CODE START --------------------------- > ... > function printAuthor() > { > global $dao; 1) Don't use a global here. That the wrong way to do this. > $dao->getLinks(); 2) Don't use getLinks(). It's not good coding. Use getLink() for the specific field you want. > return $dao->_author_id_author->nom; > } > 3) Instead of writing this yourself use the formbuilder_integration option which will do this for you. > The output should be : > > Title Author > Article 1 Administrator > Article 2 User > > > but in fact I get: > > Title Author > Article 1 Administrator > Article 2 Administrator > > Datagrid fills the author column with the first author name it finds, no matter > what are the other values. If I switch the two articles auhor names in the > table, then the author name column displays only 'User'. > > I believe that calling the 'getLinks' method inside the callback function was > the same as calling it inside the fetch loop of a DataObject. Perhaps this is > not the proper code to achieve this goal with Datagrid. Tried to use: > > $author = $dao->getLink('author_id_author'); > return $author->name; > > instead in the callback funtion with the same result. > This is because SDG gets all of the data before display happens, so the DO has the *last* record in it when the display happens. -- Justin Patrin

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