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.
Watch
GitHub Core
Show your support for Zikula! Sign up at Github account and watch the Core project!
GitHub Modules
- rgasch created topic »Using PageUtil::addVar() to load script code« 11:48 AM
- michiel responded to »password problem« 10:01 AM
- mazdev responded to »Hide "Register new account" and change template to 3 col« 07:50 AM
- mesteele101 created topic »Zikula 1.3.3 - Site Search 1.5.2 - Unable to turn off plug-ins« 07:48 AM
- mesteele101 responded to »ERR (3): E_USER_ERROR: Smarty error: [in pagesvar:pagesitem2en line XXX]…« 25. May
- mazdev responded to »Pages 2.5.0 and updating - Page not found« 25. May
- mesteele101 responded to »Zikula 1.3.3 - Selecting a category in Pages not working« 25. May
Zikula Blog
- Anatomy of Open Source Projects on Mar 07
- Continuous Review on Mar 01
- Not Invented Here on Feb 24
- How to Contribute Your Code at Github on Jan 13
- 10 Steps to Coding-Nirvana: Tips for Successful Module Writing on Nov 12
- Submitting Bug Report Tickets That Get Results on Aug 17
- Cozi Tricks #1: Syntax Highlighting on Aug 07
Login
Accessing category information, how?
-
- Rank: Softmore
- Registered: May 30, 2005
- Last visit: May 31, 2010
- Posts: 340
-
- Rank: Softmore
- Registered: May 30, 2005
- Last visit: May 31, 2010
- Posts: 340
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 -
- Rank: Registered User
- Registered: Jan 14, 2009
- Last visit: Apr 01, 2010
- Posts: 39
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 -
- Rank: Softmore
- Registered: May 30, 2005
- Last visit: May 31, 2010
- Posts: 340
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 -
- Rank: Registered User
- Registered: Jan 14, 2009
- Last visit: Apr 01, 2010
- Posts: 39
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??? -
- Rank: Softmore
- Registered: May 30, 2005
- Last visit: May 31, 2010
- Posts: 340
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. -
- Rank: Softmore
- Registered: May 30, 2005
- Last visit: May 31, 2010
- Posts: 340
So I wrote up a page about my implementation. You can find it at the link. http://community.zik…tag=CategoryExample
- Moderated by:
- Support
