1
Mazar
how to use xoopstree for creating categories and subcategoires
  • 2009/9/1 20:07

  • Mazar

  • Not too shy to talk

  • Posts: 191

  • Since: 2009/1/4 0


I am looking for a guidline or tutorial to use category system in a module. but wondering if anyone can help me how can i use xoopstree for creating categories and subcategoires?

2
urbanspacema
Re: how to use xoopstree for creating categories and subcategoires

hello I am just beginning with the development but you can look at my xsitemap module maybe can help you.

3
tank1955
Re: how to use xoopstree for creating categories and subcategoires
  • 2009/9/2 1:21

  • tank1955

  • Module Developer

  • Posts: 276

  • Since: 2007/9/7 1


I decided I wanted to use XoopsTree class for providing categories in Video Tube. The problem I found was debug generated warning that XoopsTree class had been deprecated and XoopsObjectTree should be used instead. I am sure there were good reasons for this but I found XoopsTree very easy to understand and implement so I made a copy of the class, renamed it VideoTubeTree and added it as part of the Video Tube module.

There are five components involved to add categories and subcategories to your module.
1. The class file (in my case /modules/videotube/class/videotubetree.php)
2. MySQL database table containing category data
3. Logic in index.php file to extract category data from table and place in template variables
4. Code in template file to display the category data
5. Code in admin/index.php to administer category data

I hope you find the code helpful. Be sure to download VideoTube v1.85 to explore the code.

4
Mazar
Re: how to use xoopstree for creating categories and subcategoires
  • 2009/9/2 8:15

  • Mazar

  • Not too shy to talk

  • Posts: 191

  • Since: 2009/1/4 0


Thanks i had a look at videotube 8. But i am still digging out how to use xoopsObject tree. I think XOOPS object tree is better less coding.
I am trying to learn but the same time want to follow XOOPS standard.

5
bumciach
Re: how to use xoopstree for creating categories and subcategoires
  • 2009/9/2 10:03

  • bumciach

  • Not too shy to talk

  • Posts: 153

  • Since: 2007/6/25


If you want to use XoopsObjectTree you need to get data from a database as objects at the beginning. For this purpose, creating a class object, for example Category, into file /modules/mymodule/class/category.php
For more detail: https://xoops.org/modules/newbb/viewto ... =&topic_id=68782&forum=28
(in the example below, my module is called pfxfp, you have to rename it to yours modulename!)
class pfxfpCategory extends XoopsObject
{
    
/**
     * constructor
     */
    
function pfxfpCategory()
    {
        
$this->__construct();
    }
    
    function 
__construct()
    {
        
//definitions of the table field names (which includes categories) from the database 
        
$this->initVar("id_cat"XOBJ_DTYPE_INTnullfalse);
        
$this->initVar("id_parent_cat"XOBJ_DTYPE_INTnullfalse);
        
$this->initVar('name'XOBJ_DTYPE_TXTBOXnullfalse255);
    }
}

class 
pfxfpCategoryHandler extends XoopsPersistableObjectHandler
{
    function 
pfxfbCategoryHandler(&$db)
    {
        
$this->__construct($db);
    }
    
    function 
__construct(&$db)
    {
        
parent::__construct($db'pfxfp_categories''pfxfpCategory''id_cat');
    }

    function 
getCategories($criteria=null)
    {
        if (!
is_object($criteria)) {
          
$criteria = new Criteria(null);
          
$criteria->setSort('name');
          
$criteria->setOrder('ASC');
        }
        
$ret $this->getObjects($criteria);
        return 
$ret;
    }
}

and call in a script
//initialize category class (modulename is importat!)
$obj_handler =& xoops_getModuleHandler('category''pfxfp');
//get data as objects
$objs $obj_handler->getCategories();
//transmitting data to XoopsObjectTree, the parameters ('id_cat', 'id_parent_cat') are the same as the class category
$kt = new XoopsObjectTree$objs'id_cat''id_parent_cat' );


If you want form with select categories
include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php";
$cform = new XoopsThemeForm("form title""frm");
    
$cform->setExtra('enctype="multipart/form-data"');
    
//$kt refers to XoopsObjectTree
  
$a $kt->makeSelBox"id_parent_cat""name"'-- ' ''true );
  
$cform -> addElement( new XoopsFormLabel'Categories'$a ), true );
  
$cform->display();

6
Mazar
Re: how to use xoopstree for creating categories and subcategoires
  • 2009/9/2 10:20

  • Mazar

  • Not too shy to talk

  • Posts: 191

  • Since: 2009/1/4 0


Thanks for the easy explaination. will try that.

Login

Who's Online

78 user(s) are online (49 user(s) are browsing Support Forums)


Members: 0


Guests: 78


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Aug 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits