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/viewtopic.php?viewmode=flat&type=&topic_id=68782&forum=28(in the example below, my module is called pfxfp, you have to rename it to yours modulename!)
le="color: #000000"><?php 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_INT, null, false); $this->initVar("id_parent_cat", XOBJ_DTYPE_INT, null, false); $this->initVar('name', XOBJ_DTYPE_TXTBOX, null, false, 255); } } 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
le="color: #000000"><?php //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
le="color: #000000"><?php 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();