1
banesto
Module Development tutorial (with classes)
  • 2007/1/12 11:25

  • banesto

  • Just popping in

  • Posts: 61

  • Since: 2005/1/24


Ok, there is a simple module development tutorial which i don't need because i can figure out myself how to do it, but what about more sophisticated module, which includes classes XoopsObjects, XoopsObjectHandlers? Is there a tutorial that can explain how to use all thouse rich XOOPS features and make a real smart module not just plain php code implementet in xoops???

And Yes, i've seen Dev Wiki. There are dev. standarts which i don't consider to be a tutorial, just some tips, which are too few. And there are no examples how to make a class, call it etc.
where's my red bull!

2
Dave_L
Re: Module Development tutorial (with classes)
  • 2007/1/12 11:57

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


I haven't found such a tutorial. I've had to figure out how to use those classes mostly by studying the actual code and using trial and error.

A complication is that it also depends on which version of XOOPS you're using.

3
banesto
Re: Module Development tutorial (with classes)
  • 2007/1/12 11:59

  • banesto

  • Just popping in

  • Posts: 61

  • Since: 2005/1/24


of course, i am aware of this method, but it's not so easy.. could you advise a simple module using classes for a start?

my XOOPS version is 2.0.16
where's my red bull!

4
fooups
Re: Module Development tutorial (with classes)
  • 2007/1/12 12:11

  • fooups

  • Just popping in

  • Posts: 82

  • Since: 2004/1/12


Hi,

There is two tutorials about this issue, but both are written in french.

You can find them on the french support site: XOOPS object's model and an example of XoopsObject and XoopsObjectHandler classes use.

Please note that at the end of one of the tutorials mentioned above, you will find a link to an example module at the end of the first tutorial.

Also in the dev'wiki: XoopsObject and XoopsObjectHandler.

Bye

5
banesto
Re: Module Development tutorial (with classes)
  • 2007/1/12 12:41

  • banesto

  • Just popping in

  • Posts: 61

  • Since: 2005/1/24


i wish i knew French
thanks, i'll look that through
where's my red bull!

6
Mithrandir
Re: Module Development tutorial (with classes)

Unfortunately, the French example about XoopsObject and XoopsObjectHandler usage is incorrect.

Its method of including the class definition file and then calling xoops_gethandler can be replaced with a call to xoops_getmodulehandler('sortof_name_of_class');

I say 'sortof...' because e.g. in an article module, you could call xoops_getmodulehandler('article') and XOOPS will look for a file called article.php inside the module's class folder. That file must contain a class called [module's dirname]ArticleHandler. But if it does, you don't need to include any files before calling xoops_getmodulehandler().

There are some other mistakes in that tutorial as well, but not regarding XoopsObject/XoopsObjectHandler usage.
"When you can flatten entire cities at a whim, a tendency towards quiet reflection and seeing-things-from-the-other-fellow's-point-of-view is seldom necessary."

Cusix Software

7
banesto
Re: Module Development tutorial (with classes)
  • 2007/1/12 16:53

  • banesto

  • Just popping in

  • Posts: 61

  • Since: 2005/1/24


ok, my data:

module name: acc
class file name: member_type.php
class name: MembersType
class handler name: MembersTypeHandler


class file is situated in class folder of course.

what should i change in the names and how can i call the class to start using it's functions?
where's my red bull!

8
Mithrandir
Re: Module Development tutorial (with classes)

module name: acc
class file name: memberstype.php
class name: MembersType
class handler name: AccMembersTypeHandler

Then you can get the instance of the AccMembersTypeHandler just by calling xoops_getmodulehandler('memberstype');

or - if you are in a block - xoops_getmodulehandler('memberstype', 'acc');
"When you can flatten entire cities at a whim, a tendency towards quiet reflection and seeing-things-from-the-other-fellow's-point-of-view is seldom necessary."

Cusix Software

9
banesto
Re: Module Development tutorial (with classes)
  • 2007/1/12 17:13

  • banesto

  • Just popping in

  • Posts: 61

  • Since: 2005/1/24


Thanks, that worked out!

How can i get actual results from "getObjects" function (it's in AccMembersTypeHandler class)?

function getObjects($criteria null$id_as_key false) {
        
$ret = array();
        
$limit $start 0;
        
$sql 'SELECT * FROM '.$this->db->prefix('acc_member_type');
        if (isset(
$criteria) && is_subclass_of($criteria'criteriaelement')) {
            
$sql .= ' '.$criteria->renderWhere();
            
$limit $criteria->getLimit();
            
$start $criteria->getStart();
        }
        
$result $this->db->query($sql$limit$start);
        if (!
$result) {
            return 
$ret;
        }
        while (
$myrow $this->db->fetchArray($result)) {
            
$MembersType = new MembersType();
            
$MembersType->assignVars($myrow);
            if (!
$id_as_key) {
                
$ret[] =& $MembersType;
            } else {
                
$ret[$myrow['tid']] =& $MembersType;
            }
            unset(
$MembersType);
        }
        return 
$ret;
    }


$class_handler =& xoops_getmodulehandler('memberstype');
$memberstype =& $class_handler->getObjects;

... what's next? i get $ret back, right? how can i get out results from that?
where's my red bull!

10
banesto
Re: Module Development tutorial (with classes)
  • 2007/1/12 21:52

  • banesto

  • Just popping in

  • Posts: 61

  • Since: 2005/1/24


ok, i figured it out myself

now, what's not clear is those & marks..

what is the difference:

$class_handler =& xoops_getmodulehandler('memberstype');
$class_handler xoops_getmodulehandler('memberstype');


and here

function &create($isNew true)
function 
create($isNew true)


and another question just for confirmation.. when defining a function and putting for example $id = false in the brackets like this

getAll($id = false)

means that this attribute is not necessary when calling?
where's my red bull!

Login

Who's Online

181 user(s) are online (104 user(s) are browsing Support Forums)


Members: 0


Guests: 181


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits