midgard_object_find

Posted on 2005-03-15 17:20:12 EET.

New midgard-core API function becomes a little usefull.
Library definition:

midgard_res *res;
res = midgard_object_find(MgdObject mobj);
How it works on PHP level?
Quite trivial now , simple find() method.

$amerigard = NewMidgardArticle();
$amerigard->topic = $topic_id;
$amerigard->find();
This method returns fetchables with only id assigned as object property.
Well, "only id" if you think about typical midgard php objects. There is also well known "N" , "__res__" and new property "errno".

print_r($amerigard);
NewMidgardArticle Object(
[name] => index
[N] => 6
[__res__] => Resource id #2
[errno] => 0
)
errno set to 0 is MGD_ERR_OK error string. Nothing New. The only difference: object itself handles such property.

Let's get some more objects.

while ($amerigard->fetch())
{
$old_article = mgd_get_article($amerigard->id);
}
Hmmm.... It looks like mgd_list_topic_articles() ;)

and
$amerigard = NewMidgardArticle();
$amerigard->topic = $topic_id;
$amerigard->name = "index";
$amerigard->find();
looks like mgd_get_article_by_name.

Current limitation is sitegroup being defined according to host's sitegroup and one table usage. Which means there is no way
to get full object which is multilanged for example. But it is not future limitation :)

Ah! There is another funny "feature" with errno.

$amerigard = NewMidgardArticle();
$amerigard->topic = $topic_id;
$amerigard->create();
create() method doesn't return id which happens if You use mgd_xxx_create function. Instead of that object changes itself.
So after calling create method object should have id set to id returned from mysql ( not 0 ) and errno set to 0 ( MGD_ERR_OK ). On failure object->id is set to 0 and errno is set to corresponding error number.

I wonder if this function could return full object and method like find_fast() fetchables ids.

Back

Layout Copyright © 2006 Finnish Teleservice Center Ltd Oy - Site Powered by Midgard CMS