Don't extend XoopsObjectHandler, extend XoopsPersitableObjectHandler
a very simple class located at modules/mymenus/class/menus.php:
// Author: Trabis
// URL: http://www.xuups.com
// E-Mail: lusopoemas@gmail.com
if (!defined("XOOPS_ROOT_PATH")) {
die("XOOPS root path not defined");
}
class MymenusMenus extends XoopsObject
{
/**
* constructor
*/
function MymenusMenus()
{
$this->__construct();
}
function __construct()
{
$this->initVar("id", XOBJ_DTYPE_INT);
$this->initVar('title', XOBJ_DTYPE_TXTBOX);
}
}
class MymenusMenusHandler extends XoopsPersistableObjectHandler
{
function MymenusMenusHandler(&$db)
{
$this->__construct($db);
}
function __construct(&$db)
{
parent::__construct($db, 'mymenus_menus', 'MymenusMenus', 'id', 'title');
}
}
Now to access this handler I just need to do this:
$obj_handler =& xoops_getModuleHandler('menus', 'mymenus');
I can now use $obj_handler to do any CRUD operations on my 'menus' table without need to code a single query!
Take a look at kernel/xoopsobject to see available methods. Here are SOME examples:
$obj_handler->get($id = null, $fields = null);
$obj_handler->insert(&$object, $force = true);
$obj_handler->delete(&$object, $force = false);
$obj_handler->deleteAll($criteria = null, $force = true, $asObject = false);
$obj_handler->updateAll($fieldname, $fieldvalue, $criteria = null, $force = false);
$obj_handler->getObjects($criteria = null, $id_as_key = false, $as_object = true);
$obj_handler->getAll($criteria = null, $fields = null, $asObject = true, $id_as_key = true);
$obj_handler->getList($criteria = null, $limit = 0, $start = 0);
$obj_handler->getCount($criteria);
Is very important you learn how Criteria and CriteriaCompo classes work. XPOH will take care of sanitation while managing objects but, there is no sanitation on fields that go trough the $criteria. You can look at this classes in class/criteria.php.
Here is a simple example on how object relates to object_handler after a form submit event(here we are creating a new row in database).
$this_handler =& xoops_getModuleHandler('menus','mymenus');
$obj = $this_handler->create();
$obj->setVars($_POST);
if (!$this_handler->insert($obj)){
$msg = _AM_MYMENUS_MSG_ERROR;
}else{
$msg = _AM_MYMENUS_MSG_SUCCESS;
}