Zikula: A Flexible Open Source Content Management System
home | forum | contact us

Dizkus

Bottom
Problems filling up the variable
  • Posted: 19.10.2006, 20:30
     
    jpeeri
    rank:
    Freshman Freshman
    registered:
     August 2004
    Status:
    offline
    last visit:
    15.06.08
    Posts:
    24
    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!

    --
    JaooZi
  • Posted: 19.10.2006, 20:42
     
    Simon
    rank:
    Steering Committee Steering Committee
    registered:
     December 2002
    Status:
    online
    Posts:
    13418
    What sort of problems are you having? Have you tried echoing out the SQL to check it's correct?

    --
    Regards,
    Simon

    itbegins.co.uk - Zikula Consulting

    Please read the Support Guide
  • Posted: 19.10.2006, 20:48
     
    jpeeri
    rank:
    Freshman Freshman
    registered:
     August 2004
    Status:
    offline
    last visit:
    15.06.08
    Posts:
    24
    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

    --
    JaooZi
  • Posted: 19.10.2006, 22:08
     
    jediping
    rank:
    Helper Helper
    registered:
     November 2004
    Status:
    offline
    last visit:
    12.03.07
    Posts:
    387
    Try running that SQL through your database interface and see if you can get a more useful error.
  • Posted: 20.10.2006, 02:20
     
    jpeeri
    rank:
    Freshman Freshman
    registered:
     August 2004
    Status:
    offline
    last visit:
    15.06.08
    Posts:
    24
    The problem was that there was no row. Thank you very much icon_smile

    --
    JaooZi
  • Posted: 20.10.2006, 20:02
     
    jediping
    rank:
    Helper Helper
    registered:
     November 2004
    Status:
    offline
    last visit:
    12.03.07
    Posts:
    387
    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. ;)
  • Posted: 20.10.2006, 20:53
     
    jpeeri
    rank:
    Freshman Freshman
    registered:
     August 2004
    Status:
    offline
    last visit:
    15.06.08
    Posts:
    24
    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

    --
    JaooZi
  • Posted: 20.10.2006, 23:23
     
    Simon
    rank:
    Steering Committee Steering Committee
    registered:
     December 2002
    Status:
    online
    Posts:
    13418
    Should that not be:

    Code

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


    --
    Regards,
    Simon

    itbegins.co.uk - Zikula Consulting

    Please read the Support Guide
  • Posted: 21.10.2006, 00:11
     
    jpeeri
    rank:
    Freshman Freshman
    registered:
     August 2004
    Status:
    offline
    last visit:
    15.06.08
    Posts:
    24
    It follows without working :(

    Thanks

    --
    JaooZi
  • Posted: 21.10.2006, 00:59
     
    jediping
    rank:
    Helper Helper
    registered:
     November 2004
    Status:
    offline
    last visit:
    12.03.07
    Posts:
    387
    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.
  • Posted: 21.10.2006, 01:14
     
    jpeeri
    rank:
    Freshman Freshman
    registered:
     August 2004
    Status:
    offline
    last visit:
    15.06.08
    Posts:
    24
    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');
    }


    --
    JaooZi
  • Posted: 21.10.2006, 01:51
     
    jediping
    rank:
    Helper Helper
    registered:
     November 2004
    Status:
    offline
    last visit:
    12.03.07
    Posts:
    387
    After the foreach loop in your user_view file, you need to assign $hpnprojectscats to $pnRender:

    Code

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


  • Posted: 21.10.2006, 02:27
     
    jpeeri
    rank:
    Freshman Freshman
    registered:
     August 2004
    Status:
    offline
    last visit:
    15.06.08
    Posts:
    24
    YOU ARE GOD!! THANKS!!!

    PD:I changed the --[cat.title]-- for --[cat]--

    --
    JaooZi
  • Posted: 23.10.2006, 20:52
     
    jediping
    rank:
    Helper Helper
    registered:
     November 2004
    Status:
    offline
    last visit:
    12.03.07
    Posts:
    387
    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!) :)

Extensions Moderation

Main Menu

Extensions Database

Documentation

Development

Login

Donate to Zikula