Fork me on GitHub

Accessing category information, how?  Bottom

  • I am working on a module that would fit nicely into the category functions of Zikula, However, I am having a hard time getting my head around how to save category information and how to retrieve it. I have looked at the doc page on this in the Developer Wiki, and it's still not clear how you get the information out. Here is where I am. I have been able to pull the categories from the zikula framework and display the lovely little menu on my page. I can also retrieve what category the user has selected from said page. My two questions are

    1) How do I save that information back to the database?
    2) How do I retrieve that information from the database?

    Let me know if you need more info. What I am really looking for is some code examples. And yes I have looked at Pages and New and it's still not clear to me what you need to do to push data into the database and to get data out of the database.
    Thanks in advance.
  • So after messing about with this a little more, I was able to understand how it gets saved. (I found I need to set enable_categorization to true in my code, which was an alteration of the Pages module code I was going from). So now it will save the data to the database and I can pull it back.

    Code

    // Enable categorization services
        $pntable['quickcheck_quest_db_extra_enable_categorization'] = true;
        $pntable['quickcheck_primary_key_column'] = 'id';



    Now my next problem is to get the template to read the category data correctly and set up the menu when it gets passed category data. I have been able to get the data back out of the database with a call to the right ID. How do I set up this template? Below is example code straight from the Docs. In other words, can someone walk me through this code? Thanks

    Code

    <div class="pn-formrow">
        Category
        <!--[nocache]-->
        <ul>
        <!--[foreach from=$catregistry key=property item=category]-->
            <!--[array_field_isset assign="selectedValue" array=$__CATEGORIES__ field=$property returnValue=1]-->
            <li><!--[selector_category category=$category name="TABLENAME[__CATEGORIES__][$property]" field="id" selectedValue=$selectedValue defaultValue="0"]--></li>
        <!--[/foreach]-->
        </ul>
        <!--[/nocache]-->
    </div>




    edited by: Paustian, datetimebrief
  • I manually got the data from the categories and depending on the data to create a menu
    the result can be found at www.mirdusha.ru the right side but there is in Russian
  • Eugeny,

    Thanks for the reply and that seems like a reasonable way to proceed. They have some nice templates in the pages module and News module, but I cannot get my head around them. I was just hoping someone could walk me through how to set them up.



    edited by: Paustian, datetimebrief
  • Code

    if (!($class = Loader::loadClass('CategoryUtil'))) {
            return LogUtil::registerError ('Unable to load class CategoryUtil ... exit');
        }

        if (!($class = Loader::loadClass('CategoryRegistryUtil'))) {
            return LogUtil::registerError ('Unable to load class CategoryRegistryUtil ... exit');
        }
       
       
       
        $catID = CategoryRegistryUtil::getRegisteredModuleCategory ('YouModule', $table, $type);
        if (!$catID) {
            return LogUtil::registerError ('Unable to determine root category ID ... exit');
        }
       
        $category = CategoryUtil::getCategoryByID ($catID);
        if (!$category) {
            return LogUtil::registerError ('Unable to retrieve root category ... exit');
        }
        $allCats  = CategoryUtil::getSubCategoriesForCategory ($category, true, true, false, true, false, null, '', null, 'sort_value, id, desc');
        if (!$allCats) {
            return LogUtil::registerError ('Unable to retrieve category tree ... exit');
        }
       
        pnRander->Assign('allcats',$allCats);

    $allCats have all category and sub category, as you wish

    now in template you must disassemble all as needed, for example:

    Code

    <div class="pn-formrow">
        Category
        <!--[nocache]-->
        <ul>
        <!--[foreach from=$allcats key=property item=category]-->
           
            <li><!--[ $category.id|pnvarprephtmldisplay ]--> => <!--[ $category.display_name.ru|pnvarprephtmldisplay ]--></li>
        <!--[/foreach]-->
        </ul>
        <!--[/nocache]-->
    </div>


    what you want to do with this modules???
  • Thanks Eugeny, That gave me the place to start. It's all working with category goodness! I will try to document the solution I came up with in the next few days in the Wiki to try and make the learning curve a little less steep for those who come after me.
  • So I wrote up a page about my implementation. You can find it at the link. http://community.zik…tag=CategoryExample

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