Fork me on GitHub

Grabbing tables from other modules  Bottom

Go to page 1 - 2 [+1]:

  • I need to use info stored in tables that are not defined in the module I am editing, but whenever I try to load the API from a different module I get an error. I am new to postnuke and don't know how to use information from other modules. Am I missing something simple? Thanks.
  • No need to load an API when all you need is the tables, huh? Make the queries directly.
  • It's best to use the module API to load data from said module, it's easier. What is the code you're using.

    Also moved this to the right forum.

    --
    Home Page | Find on Facebook | Follow on Twitter
  • Thanks Michael...I was starting to wonder if I was going to learn something today or not. ;)
  • function foodmanagement_admin_view() {

    $dbconn =& pnDBGetConn(true);
    $pntable =& pnDBGetTables();
    // Get parameters from whatever input we need. All arguments to this
    // function should be obtained from pnVarCleanFromInput(), getting them
    // from other places such as the environment is not allowed, as that makes
    // assumptions that will not hold in future versions of PostNuke


    $startnum = pnVarCleanFromInput('startnum');

    // Create output object - this object will store all of our output so that
    // we can return it easily when required
    $output =& new pnHTML();

    // if (!pnSecAuthAction(0, 'FoodManagement::', '::', ACCESS_EDIT)) {
    // $output->Text(_SKCONFIGNOAUTH);
    // return $output->GetOutput();
    // }

    // Add menu to output - it helps if all of the module pages have a standard
    // menu at their head to aid in navigation
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(foodmanagement_adminmenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Title - putting a title ad the head of each page reminds the user what
    // they are doing
    $output->Title(_VIEWSKCONFIG);

    // Load API. Note that this is loading the user API, that is because the
    // user API contains the function to obtain item information which is the
    // first thing that we need to do. If the API fails to load an appropriate
    // error message is posted and the function returns
    if (!pnModAPILoad('FoodManagement', 'user')) {
    $output->Text(_LOADFAILED);
    return $output->GetOutput();
    }

    // The user API function is called. This takes the number of items
    // required and the first number in the list of all items, which we
    // obtained from the input and gets us the information on the appropriate
    // items.
    $items = pnModAPIFunc('SKConfig',
    'user',
    'getall');


    foreach ($items as $item){
    $output->Text($item['date']);
    }


    return $output->GetOutput();

    }




    I need to use the SKConfig module's tables but this isn't letting me do it, and if I try to load SKConfig's API above it errors on me. I have all of this wrong conceptually, but I can't figure it out...I know the getall function works correctly, but it isn't returning with anything...in fact, if i change the function name to anything else it still runs...it just doesn't return anything, leading me to believe that it isn't even getting that far to check whether or not it is a valid function.

    I don't know how else to get the table info from SKConfig. Thanks.
  • If calling the API doesn't work (and I've had problems trying to use the UpDownload program as I want, 'cause it's not API compliant) and you need to get information from that table, you need to make sure you copy the relevant table definition code from the pntables file. Then you should be able to access it and display it as you would your own tables.

    And as Mark would say, the pnHTML code is deprecated, so you might want to look at pnRender. :D
  • jediping

    Iyou need to make sure you copy the relevant table


    No.... If a module has it's own pntables file then this can be loaded with pnModDBInfoLoad('<modname>');

    -Mark

    --
    Visit My homepage and Zikula themes.</modname>
  • Oooooo, really????? Yay! I didn't know about that one. Wooot! I'll mod my code as soon as I get to work. :)
  • jediping

    Oooooo, really????? Yay! I didn't know about that one. Wooot! I'll mod my code as soon as I get to work. :)


    You don't see it that much since the core loads the table information (by calling this very API) for API compliant modules. However it's useful for non
    API compliant module, search plugins, blocks etc.

    It is documented in the API reference though....

    -Mark

    --
    Visit My homepage and Zikula themes.
  • Mark,

    Do you know of any modules that incorporate the pnModDBInfoLoad('<modname>'); function ?

    -Lobos

    --
    -Lobos
    Professional PHP Framework Services: Concept, Development and Deployment</modname>
  • Lobos,

    Not off the top of my head since pnModAPILoad and pnModLoad call pnModDBInfoLoad intermally so, in general, it's not required. Where you will need it is

    a) in a search plugin for a module with it's own pntables file
    b) in a block which contains direct SQL queries rather than calls to module API's

    The only place I can think of where it's used in the ezcomments block.

    -Mark

    --
    Visit My homepage and Zikula themes.
  • So... to make sure, I can just use this anywhere in a module, not just on the pntables page? Haven't had a chance to check it out, and might not, since I have to switch servers, which means a lot of annoying downloading, but I'll be giving it a go once I have the time.
  • I just want to make sure that I get everything straight here...(sorry)

    1) my call to pnModAPIFunc('SKConfig', 'user', 'getall'); should not work because that function is in a different module and that is not allowed

    2) instead, i need to call pnModDBInfoLoad('SKConfig');, but then how do I use this?


    Thanks again.
  • @jediping - take a look at the EZComments block I refernced lobos too. It shows how you'd use it. Basically you call pnModDBInfoLoad before you call pnDBGetTables. The order isn't 100% necessary since we used a reference to the pntables array but it makes more sense this away

    @fritzd - No - you can (and should where necessary) call other module API's. As long as you make sure you load the correct API first via pnModAPILoad (.760 won't need this as API's will autoload on demand).

    -Mark

    --
    Visit My homepage and Zikula themes.
  • The API reference

    Though some of the sentences and code seem to just end...

Go to page 1 - 2 [+1]:

  • 0 users

This list is based on users active over the last 60 minutes.