Fork me on GitHub

Newbie - Help on develloping module  Bottom

  • Hello all, i create a module (called SGUnivers) and now i would like to add a variable (called pn_points and add in database) in users so i see on documentation the function pnuser but i don't know how can i use it icon_confused Like this ?

    Code

    $points = pnUserGetVar('pn_points';-1);
    return $points;

    This code must go to adminapi.php

    In my page SGUnivers_admin_view.htm I must include this

    Code

    <!--[points]-->


    But my problem is that i don't know how code i must input in admin.php. Can you help me please ???

    Thanks
  • Hi!
    First, i guess you need to be clear in the flow of the "MVC" architecture on Zikula:
    pnuser.php (or pnadmin.php) are the entry points or "Controllers",
    the ones that receives the parameters, passes them to the Model (APIs) and return an Output.

    So, a controller function basically does something like:

    Code

    function MyModule_type_showPoints($args) {
        // get the input parameters
        $uid = FormUtil::getPassedValue('uid')

        // validate the uid, if empty takes the current user id
        if (empty($uid)) {
            $uid = -1;
        }

        // get the item through the model
        $points = pnModAPIFunc('MyModule', 'user', 'getpoints', array('uid' => $uid))
        // or just
        $points = pnUserGetVar('pn_points', $uid)

        // if there's no item return an error
        if ($points === false) {
            return LogUtil::registerError(_NOSUCHITEM, 404);
        }

        // build the output
        $renderer = pnRender::getInstance('MyModule');
        // assign the item data to the template
        $renderer->assign('points', $points)
        // return the output
        return $renderer->fetch('mymodule_type_showpoints.htm')
    }


    So, as clean as possible, get the parameters, use the model and build the output.
    You can render the points value with:

    Code

    <!--[$points]-->


    Code

    <!--[points]-->
    The code above is a Smarty plugin call (requires that the file /modules/MyModule/pntemplates/function.points.php exists and deifned the plugin work). Inside a plugin you can call the adminapi method (or pnUserGetVar) too, and return the user points.

    Anyways, the man that i know worked with this stuff a lot is Topiatic.
    You should check his RosterMaster module @CoZi

    Greetings

    --
    - Mateo T. -
    Mis principios... son mis fines
  • Hello,

    Module that you speak is off, i can see demo but not the code icon_confused
    My english is poor and i have realise that's beginning whith modulestudio but

    That i have understand is:
    I have 2 solutions :
    - first : I create a file function.points.php in /modules/SGUnivers/pntemplates/plugins/

    Code

    function SGUnivers_admin_showPoints($args)
    {
        $uid = FormUtil::getPassedValue('uid')
        if (empty($uid)) {
            $uid = -1;
        }
        $points = pnUserGetVar('pn_points', $uid)
        if ($points === false) {
            return LogUtil::registerError(_NOSUCHITEM, 404);
        }
        $renderer = pnRender::getInstance('SGUnivers');
        $renderer->assign('points', $points)
        return $renderer->fetch('SGUnivers_admin_header.htm')
    }


    Sgunivers_admin_header.htm

    Code

    <!--[points]-->


    But after that i don't know what can i do because it doesn't work. Have you got another module that i can vie for exemple, please.

    Thanks you
  • Please just take 5 minutes, i don't see what's wrong
  • Answered on IRC, but for reference please read the module developer Wiki http://community.zik…g-DeveloperDocs.htm particularly the "Module authoring" section.

    Drak

    --
    Zikula Lead Developer
    Board Member of the Zikula Foundation
    Follow me on twitter.com/zikuladrak

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