Hey all in the process of building my next module I have stumbled across a problem I am not quit sure how to overcome, so I come to you all for advice. I have a form built and I am currently populating fileds with user name and email address using the pnUserGetVar API call, this works awesome thanks to the help from you all on this one. Now what I need to be able to do is grab a phone number for the given user from another modules table so the problem is how to accomplish this without doing an API call inside the fucntion. Is this a place where hooks should be used, and if so does anyone have an example of doing a procedure like this?
Thanks all
-SUNADMN
Watch
GitHub Core
Show your support for Zikula! Sign up at Github account and watch the Core project!
GitHub Modules
- mesteele101 responded to »ERR (3): E_USER_ERROR: Smarty error: [in pagesvar:pagesitem2en line XXX]…« 07:01 AM
- mazdev responded to »Pages 2.5.0 and updating - Page not found« 06:41 AM
- ehdwma created topic »Hide "Register new account" and change template to 3 col« 06:27 AM
- mesteele101 responded to »Zikula 1.3.3 - Selecting a category in Pages not working« 01:29 AM
- mdee created topic »How to implement returnpage ?« 01:00 AM
- nestormateo responded to »Fillters in Clip« 24. May
- damon responded to »Can the Updated Version Check be Turned Off (Z 1.3)« 24. May
Zikula Blog
- Anatomy of Open Source Projects on Mar 07
- Continuous Review on Mar 01
- Not Invented Here on Feb 24
- How to Contribute Your Code at Github on Jan 13
- 10 Steps to Coding-Nirvana: Tips for Successful Module Writing on Nov 12
- Submitting Bug Report Tickets That Get Results on Aug 17
- Cozi Tricks #1: Syntax Highlighting on Aug 07
Login
Loading data from other modules into form fileds?
-
- Rank: Legend
- Registered: Dec 11, 2002
- Last visit: Oct 21, 2009
- Posts: 11674
You want to call the API function of another module?
Code
--
itbegins.co.uk - Zikula Consulting
birtwistle.me.uk - Personal Blog
Please read the Support Guide -
- Rank: Developer
- Registered: Jun 16, 2003
- Last visit: May 29, 2010
- Posts: 1966
in .760 you don't have to load the API first, it is automatically loaded when the function is called. -
- Rank: Legend
- Registered: Dec 11, 2002
- Last visit: Oct 21, 2009
- Posts: 11674
Yep, but presuming you want to be backwards compatible ;)
--
itbegins.co.uk - Zikula Consulting
birtwistle.me.uk - Personal Blog
Please read the Support Guide -
- Rank: Developer
- Registered: Jun 16, 2003
- Last visit: May 29, 2010
- Posts: 1966
-
- Rank: Legend
- Registered: Dec 11, 2002
- Last visit: Oct 21, 2009
- Posts: 11674
Well I am - all my recent new modules call the Groups module API at some point, so .760 only here....
--
itbegins.co.uk - Zikula Consulting
birtwistle.me.uk - Personal Blog
Please read the Support Guide -
**unknown user**
- Rank: Softmore
- Registered: Mar 16, 2002
- Last visit: Oct 21, 2009
- Posts: 413
No the object is not going to call an API call of another module, yet rather talk directly to the other modules ( pnAddressbook ) tables to gather info ( phone number ). I would need to actually do a SQL query against the other modules table like so:
Code
$sql = SELECT $element FROM nuke_pnAddressbook_address WHERE CONCAT($address_column[fname],' ',$address_column[lname]) = $uname;
Something to that effect, but do I have to write an API call that will talk to the other DB or can this be done right in the function??
Thanks all
-SUNADMN -
**unknown user**
- Rank: Softmore
- Registered: Mar 16, 2002
- Last visit: Oct 21, 2009
- Posts: 171
i'm not sure, and by no means an expert on this. But i think as far as i know you can make an API function in you're module, and load the tables from the addressbook module.
Code
// Get datbase setup
$dbconn =& pnDBGetConn(true);
$pntable =& pnDBGetTables();
$exampletable = $pntable['example'];
$examplecolumn = &$pntable['example_column'];
$addresstable = &$pntable['pnaddressbook_address'];
$addresscolumn = &$pntable['pnaddressbook_address_column'];
$sql = "SELECT * from $exampletable, $addresstable
Might be wise to check if pnAddressBook is installed before you make the query. There is a function like modAvailable(modname) or something like that. -
- Rank: Legend
- Registered: Dec 11, 2002
- Last visit: Oct 21, 2009
- Posts: 11674
You'd need to load the module's pntable array first. I can't remember the function call offhand, but it's something like pnModDBLoadInfo('themod')
--
itbegins.co.uk - Zikula Consulting
birtwistle.me.uk - Personal Blog
Please read the Support Guide -
**unknown user**
- Registered: Mar 16, 2002
- Last visit: Oct 21, 2009
- Posts: 1097
The microsecond you'll gain is not worth it in my opinion...
Code
if (pnModAvailable('pnAddressBook')) {
// If a API function exists, take it instead of loosing time
if (!pnModAPILoad('pnAddressBook', 'user')) {
pnSessionSetVar('errormsg', 'pnAddressBook load failed')
return false;
}
// You could do an else here
// pnModDBInfoLoad('pnAddressBook');
// And buil your query bla bla bla bla...
$pnabinfo = pnModAPIFunc('pnAddressBook', 'user', 'getuserinfo', array('uname' => $uname));
if ($pnabinfo['phone'] != "") {
// You have your phone
} else {
// No phone....
}
}
//etc... etc...
;) -
- Rank: Legend
- Registered: Dec 11, 2002
- Last visit: Oct 21, 2009
- Posts: 11674
Yep, you are much better using the API of a module. But, if that's not available, all pnModDBInfoLoad does is include the module's pntables.php file, if I remember correctly..
--
itbegins.co.uk - Zikula Consulting
birtwistle.me.uk - Personal Blog
Please read the Support Guide
- Moderated by:
- Support
