Re: How to connect 2 Dynamic Objects ?
[email protected] (mikespub) Sun, 22 Jun 2003 10:09:58 GMT
| Newsgroups | gmane.comp.cms.xaraya.knowledge-base |
|---|---|
| Organization | Not much, really... |
| Message-ID | <[email protected]> |
In article <bd2ouj$bhg$1-111RdWWlOxkOkXtL6OYfHgC/[email protected]>, [email protected] (eolica) wrote: >Hannes wrote: >> i saw here the Howto from eolica to add an publiction type "contact". >> (03/06/03) >> How can i connect the Contact with the Contries Object , so that i can use >> an DropDown-Box in the >> ContactForm to choose an Country? > >If you want just the country names, you don't need another publication. >Just use a simple dropdown and include the list of the countries in the >Validation (Italy; France; Germany; ...). > >If your needs are wider (let say: you want to store the countries and get >also the associated images for flags) its another story. > >In my understanding relations to other publications are not implemented >(yet?) > >Sesto Right, there's no built-in support for relationships between objects, but you can easily maintain the relationship yourself, e.g. as follows : 1) create a function <mymodule>_userapi_getcountries that returns an array of id => name pairs for your countries. [Example : modules/dynamicdata/xarutilapi/demolist.php] If countries are objects too, you'll probably want to retrieve the id's and names via something like : $items = xarModAPIFunc('dynamicdata','user','getitems', array(// your module 'modid' => 123, // itemtype that corresponds to your countries 'itemtype' => 1, // fields you're interested in here 'fieldlist' => array('myid','myname'))); Otherwise, just return some predefined list of countries... 2) in your contacts object, specify the country property as a dropdown list and give it the validation xarModAPIFunc('mymodule','user','getcountries') 3) in your functions and templates, you can enforce the parent-child relationship via e.g. the country id. For instance, if you want to display the country and view the contacts in that country : <!-- display or retrieve or whatever ... the country --> <xar:data-display module="mymodule" itemtype="1" itemid="$countryid" /> <!-- list or retrieve or whatever ... the contacts for that country --> <xar:data-view module="mymodule" itemtype="2" where="countryid eq $countryid" /> <!-- note : you may need to define the where clause in your function and pass on a $where variable here - try it out :) --> Or use any of the other methods shown in the dyn_example module to retrieve the objects you want in a particular page... Mike.