Fork me on GitHub

Problems filling up the variable  Bottom

  • I have problems filling up the variable that would have to contain the data of the table of the data base

    This is the source code:

    Code

    function hpnProjects_userapi_getallcats($args)
    {
        // Extraemos los argumentos
        extract($args);

        $cats = array();

        // Chequeo de seguridad
        if (!pnSecAuthAction(0, 'hpnProjets::', '::', ACCESS_READ)) {
            return $cats;
        }

        // Conectamos con la base de dato
        $dbconn =& pnDBGetConn(true);
        $pntable =& pnDBGetTables();

        // Llamamos a la tabla y a la columna
        $categories_table = $pntable['hpnprojects_categories'];
        $categories_table_column = &$pntable['hpnprojects_categories_column'];

        // Obtenemos los items
        $sql = "SELECT $categories_table_column[cid],
                       $categories_table_column[title],
                       $categories_table_column[image]
                FROM $categories_table
                ORDER BY $categories_table_column[cid]"
    ;

        $result = $dbconn->Execute($sql);

        // Chequeamos que no haya errores o devolvemos el mensaje adecuado
        if ($dbconn->ErrorNo() != 0) {
            pnSessionSetVar('errormsg', _GETFAILED);
            return false;
        }
       
        for (; !$result->EOF; $result->MoveNext()) {
            list($cid, $title, $image) = $result->fields;
            if (pnSecAuthAction(0, 'hpnProjects::', "$cid::", ACCESS_READ)) {
                $cats[] = array('cid' => $cid,
                                 'title' => $title,
                                 'image' => $image);
            }
        }

        // Retornamos las categorias
        return $cats;
    }



    You check that there isn't any error, please.

    Thanks!
  • What sort of problems are you having? Have you tried echoing out the SQL to check it's correct?

    --
    itbegins.co.uk - Zikula Consulting

    birtwistle.me.uk - Personal Blog


    Please read the Support Guide
  • The problem is _HPNPROJECTS_CATFAILED:

    Code

    if (!$cats) {
            return pnVarPrepHTMLDisplay(_HPNPROJECTS_CATFAILED);
        }


    The $SQL variable return: SELECT pn_cid, pn_title, pn_image FROM pn_hpnprojects_categories ORDER BY pn_cid
  • Try running that SQL through your database interface and see if you can get a more useful error.
  • The problem was that there was no row. Thank you very much icon_smile
  • No problem. Glad it was easy to find! I get stupid comma errors that I can't see because I just am not used to looking for them, and I tear my hair out before I find them, then feel dumb walking around bald. ;)
  • I have another problem. It doesn't print the things in screen. This it is hpnprojects_user_view.htm:

    Code

    <!--[include file="hpnprojects_user_menu.htm"]-->

    <div class="example_itemlist">
    <!--[* Loop through the items and display them   *]-->
    <ul>
    <!--[foreach item=cats from=$cats]-->
    <li><!--[$cats]--></li>
    <!--[/foreach]-->
    </ul>
    </div>


    Thanks
  • Should that not be:

    Code

    <!--[foreach item=cat from=$cats]-->
    <li><!--[$cat]--></li>
    <!--[/foreach]-->


    --
    itbegins.co.uk - Zikula Consulting

    birtwistle.me.uk - Personal Blog


    Please read the Support Guide
  • It follows without working :(

    Thanks
  • I think the problem, in addition to the cat vs. cats issue, is that your new $cat variable will be an array.

    Code

    <!--[foreach item=cat from=$cats]-->
    <li><!--[$cat.title]--></li>
    <!--[/foreach]-->


    That should show you the title of the category.
  • it doesn't work. In case it serves to you, this is the pnuser.php function:

    Code

    function hpnProjects_user_viewcats($args)
    {
        // Chequeo de seguridad
        if (!pnSecAuthAction(0, 'hpnProjects::', '::', ACCESS_OVERVIEW)) {
            return pnVarPrepHTMLDisplay(_MODULENOAUTH);
        }


        // Llamamos a la funcion API
        $cats = pnModAPIFunc( 'hpnProjects',
                              'user',
                              'getallcats');

        // Comprobamos que se ha rellenado la variable cats. Si no devolvemos el mensaje apropiado  
        if (!$cats) {
            return pnVarPrepHTMLDisplay(_HPNPROJECTS_CATFAILED);
        }

        // Create output object
        $pnRender =& new pnRender('hpnProjects');

        // Loop through each item and display it.
        // Note that we do NOT use pnVarPrepForDisplay, pnVarCensor or anything like
        // that here as this is left to the template to simplify the code.
        $hpnprojectscats = array();
        foreach ($cats as $cat) {
            if (pnSecAuthAction(0,
                                'hpnProjects::',
                                "$cat[cid]::",
                                ACCESS_READ)) {
                $pnRender->assign($cat);   
                $hpnprojectscats[] = $pnRender->fetch('hpnprojects_user_row_read.htm', $cat['cid']);           
            }
        }
        // Return the output that has been generated by this function
        return $pnRender->fetch('hpnprojects_user_view.htm');
    }
  • After the foreach loop in your user_view file, you need to assign $hpnprojectscats to $pnRender:

    Code

    $pnRender->assign('cats', $hpnprojectscats);


  • YOU ARE GOD!! THANKS!!!

    PD:I changed the --[cat.title]-- for --[cat]--
  • Heh. Any time. It took me quite a few months to learn how to look for the source of problems when making my modules. Always happy to share what I've learned. (Too happy, my friends probably think!) :)
  • 0 users

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