Subject:*
<
Name/Email:*
<
Message Icon:*
<
Select*
<
Message:*
<



Click the Preview to see the content in action.
Options:*
<
Confirmation Code*
<
2 - 1 = ?  
Input the result from the expression
Maximum attempts you can try: 10
*
<
   

Re: how can i create and use xoops object handler in my module?
by bumciach on 2009/9/1 12:41:06

Thanks for your reply Trabis.
Next question :) Is this way (adding 'fake' vars for object) and with XoopsModel can we do join more than the two tables?
Or better "manually" type in the SQL query for linking multiple tables and return data in a regular array without this object mapping?
Re: how can i create and use xoops object handler in my module?
by trabis on 2009/8/29 19:23:20

The object is populated with the object vars only.

You can create 'fake' vars for your object
$this->initVar("fieldfromothertable", XOBJ_DTYPE_INT, 0, false);


Re: how can i create and use xoops object handler in my module?
by bumciach on 2009/8/29 18:47:27

I have two related tables, which I would like to get data through XoopsPersistableObjectHandler.

le="color: #000000"><?php class pfawlAutorHandler extends XoopsPersistableObjectHandler { function getAutorzy($criteria=null) { $osoba_handler = xoops_getModuleHandler('osoba'); $this->field_link = $osoba_handler->keyName; $this->field_object = "FKid_osoby"; $this->table_link = $osoba_handler->table; $ret = $this->getByLink($criteria); return $ret; } }

and my script
le="color: #000000"><?php $autor_handler = xoops_getmodulehandler('autor'); $objs = $autor_handler->getAutorzy();


I can see in the logger that the SQL query is submitted correctly. Fired directly in the database returns the contents of both tables. But $objs contains the fields from only one table.
I do not know if this is possible (using getByLink method).
Re: how can i create and use xoops object handler in my module?
by tcnet on 2009/6/29 11:56:46

Trabis,
Thanks very much for this explanation. I have searched for XoopsObject and module handler instruction for a long time. As far as I know this is the first understandable explanation of the module handler published here. I know you are very busy with core upgrades, your modules and your sites, so I appreciate you taking the time to publish this very informative post.

Suggestion to the moderator: This topic could be moved to the Wiki, FAQ's or at least made sticky so that it does not get lost in the forum's abyss.

Re: how can i create and use xoops object handler in my module?
by trabis on 2009/6/26 0:03:41

The handler implements classes listed on class/model
The getAll method is listed in model/read.php

Take a look:
le="color: #000000"><?php /** * get all objects matching a condition * * @param object $criteria {@link CriteriaElement} to match * @param array $fields variables to fetch * @param bool $asObject flag indicating as object, otherwise as array * @param bool $id_as_key use the ID as key for the array * @return array of objects/array {@link XoopsObject} */ function &getAll($criteria = null, $fields = null, $asObject = true, $id_as_key = true)


As you see this method returns an array of objects or an array of arrays(depending on how you set $asObject)

Even if you are expecting one single result you will have to use:
le="color: #000000"><?php $obj[0]->getVar("title"); //and not getVars, getVars return an array and not the field, it does not even accept arguments.



But if you want objects there is no need to use getAll()
You can do this:
le="color: #000000"><?php $obj_handler =& xoops_getModuleHandler('audio','audio'); $objs = $obj_handler->getObjects(null, true); //no criteria and use key(in this case 'id') for each array foreach ($objs as $key => $obj) { echo "<tr class='odd'><td>".$obj->getVar('source')."</td> <td>".$key/*or $obj->getVar('id')*/."</td> <td>".$obj->getVar('title')."</td> <td>".$obj->getVar('type')."</td> <td>".$obj->getVar('date')."</td></tr>"; }


if you do not need key:

le="color: #000000"><?php $obj_handler =& xoops_getModuleHandler('audio','audio'); $objs = $obj_handler->getObjects(); foreach ($objs as $obj) { echo "<tr class='odd'><td>".$obj->getVar('source')."</td> <td>".$obj->getVar('title')."</td> <td>".$obj->getVar('type')."</td> <td>".$obj->getVar('date')."</td></tr>"; }


or if you prefer (good for assign to a template or to a block):

le="color: #000000"><?php $obj_handler =& xoops_getModuleHandler('audio','audio'); $objs = $obj_handler->getObjects(); foreach ($objs as $obj) { $array = $obj->getValues(); //$block['content'] = $array; //$xoopsTpl->assign('content', $array); echo "<tr class='odd'><td>".$array['source']."</td> <td>".$array['title']."</td> <td>".$array['type']."</td> <td>".$array['date']."</td></tr>"; }


Notice the use of getValues instead of getVars.
getVars does no sanitation for display while getValues does!

Who's Online

183 user(s) are online (139 user(s) are browsing Support Forums)


Members: 0


Guests: 183


more...

Donat-O-Meter

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

Latest GitHub Commits