By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,512 Members | 3,790 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,512 IT Pros & Developers. It's quick & easy.

"Modular site" mod writers name vars or use ident supplied by app

P: n/a
I'm writing a test "modular site". So far I have created an App class,
a Module Manager class and a couple of test modules.

The Manager looks in a directory called 'modules' and then for every
..php file is try to create a class of type <filenameminus the .php, so
eg. for testmodule.php it tries to create a class "testmodule" and puts
it into an array within the module manager called $_modules

Module Manager has a dispatch_message function which accepts an ID for
the type of message to send, which recurses through the modules in
$_modules and uses their ReceiveMessage function to send them the message.

example:

public function dispatch_message( $message_id ) {
foreach ( $this->_modules as $module ) {
$module->ReceiveMessage( $message_id );
}
}

This is all working well and good, the thing I'm wondering about is when
modules want to postback information, should i rely on module users
naming their form inputs specifically to their module, or should my app
(when register the modules) supply a module with a unique 'ident' that
the module writer should then check for in their code and all for in
their forms etc.

eg., should i force module writers to make forms as such:

<input type="text" name="<?phpecho $mymodules->ident()?>_username"
value="" />

How do these modular sites normally differentiate from one modules POSt
to anothers?
Apr 7 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Tyno Gendo wrote:
should i rely on module users naming their form inputs specifically to
their module, or should my app (when register the modules) supply a
module with a unique 'ident' that the module writer should then check
for in their code and all for in their forms etc.
The latter route sounds like a good idea. For my current project though, I
went the former route, though in my API document, I've described a naming
convention (similar to the naming convention used by Java packages) to
avoid naming collisions between different modules.

The convention is like this: say I'm writing a module that does "foo" for
the package, and I own the domain name "tobyinkster.co.uk", then I'd name
my module:

uk_co_tobyinkster_foo

If my module needed to create, say, form input fields, it would make sure
they used "uk_co_tobyinkster_foo" as a prefix for the field names. If it
wanted to generate some HTML output using some "class" or "id" attributes,
then it would similarly prefix them.

If a module user didn't own their own domain name, they could simply use
their e-mail address:

com_hotmail_at_joebloggs_foo

Although you do end up with some fairly ugly-looking module names, this is
a pretty sure-fire way to avoid naming collisions. Because of the ugly
names, in my plugin registration function, I do allow plugin authors to
provide a "friendly" name for their plugin, which is displayed anywhere a
user is likely to see it. I also allow them to provide a link, the author's
name, some version information and so on.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Apr 8 '07 #2

P: n/a
Toby A Inkster wrote:
<snip>
If a module user didn't own their own domain name, they could simply use
their e-mail address:

com_hotmail_at_joebloggs_foo

Although you do end up with some fairly ugly-looking module names, this is
a pretty sure-fire way to avoid naming collisions. Because of the ugly
names, in my plugin registration function, I do allow plugin authors to
provide a "friendly" name for their plugin, which is displayed anywhere a
user is likely to see it. I also allow them to provide a link, the author's
name, some version information and so on.
Thanks for that reply, useful. I think I will go with supplying an
ident to each module as it registers, using the code from uniqid example:

$ident = md5(uniqid(rand(), true));

This will created the ident and call the module (see below) on creation
with $module->SetModuleIdentifier($ident);

Then a module writer can use the ident as prefix to forms/session values
etc.

PRESENTATION
------------

What's the best way of handling where a module loads in terms of
presentation??? I notice most "modular" sites has presentation areas,
such as header, menu, user_menu, footers etc.

So best way to handle is to have a module specify where it wants to
appear on creation???

eg. test module below should have something like the following which the
module registration utiltity could call after creation to find out where
this modules sits???

function GetPlacement() {
return OBJ_PLACEMENT_USERMENU;
}
MESSAGING VS. HOOKS??
---------------------

I was thinking of using a messaging system to alert modules that they an
event has happened but other people seem to have a hook's based system
where modules say they want to handle an event in advance, what's the
pro's and con's ??

I'm thinking of handling like so:

<?php
class testmodule {

function SetModuleIdentifier( $id ) {
// TODO:
}

function ReceiveMessage( $messageid ) { TODO: add $params

switch($messageid) {

case MSG_APPLICATION_PAGELOAD:
echo "Hello from module 1!\n";
break;

case MSG_APPLICATION_PAGERENDER:
if ( $_SERVER["REQUEST_METHOD"]<>"POST" ) {
?>
<p>
<form action="<?php echo $_SERVER["PHP_SELF"]?>"
method="post">
Please chose a registered name
<input type="text" name="username" value="" />
<input type="submit" name="submit" />
</form>
</p>
<?php
}
else {
?>
<p>
You chose the registered name <?php echo
$_POST["username"]; ?>
</p>
<?php
}
break;

case MSG_APPLICATION_PAGEUNLOAD:
echo "Goodbye!\n";
break;

}

}

}
?>
Apr 9 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.