| Justin Patrin 2006-03-23, 7:01 pm |
| 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 a=
n
> 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 th=
e
> 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 thi=
s is
> not the proper code to achieve this goal with Datagrid. Tried to use:
>
> $author =3D $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
|