midgard_object_find
Posted on 2005-03-15 17:20:12 EET.
New midgard-core API function becomes a little usefull.
Library definition:
Quite trivial now , simple find() method.
Well, "only id" if you think about typical midgard php objects. There is also well known "N" , "__res__" and new property "errno".
Let's get some more objects.
and
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.
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.
Library definition:
midgard_res *res;How it works on PHP level?
res = midgard_object_find(MgdObject mobj);
Quite trivial now , simple find() method.
$amerigard = NewMidgardArticle();This method returns fetchables with only id assigned as object property.
$amerigard->topic = $topic_id;
$amerigard->find();
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);errno set to 0 is MGD_ERR_OK error string. Nothing New. The only difference: object itself handles such property.
NewMidgardArticle Object(
[name] => index
[N] => 6
[__res__] => Resource id #2
[errno] => 0
)
Let's get some more objects.
while ($amerigard->fetch())Hmmm.... It looks like mgd_list_topic_articles() ;)
{
$old_article = mgd_get_article($amerigard->id);
}
and
$amerigard = NewMidgardArticle();looks like mgd_get_article_by_name.
$amerigard->topic = $topic_id;
$amerigard->name = "index";
$amerigard->find();
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();create() method doesn't return id which happens if You use mgd_xxx_create function. Instead of that object changes itself.
$amerigard->topic = $topic_id;
$amerigard->create();
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.