Date index for Mar 2003
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Overloaders [was: Re: [achievo] SQL schema evolution issue]
Hi,
Jonas Lincoln wrote:
It seems as though only the modifiers-code is included in 0.9.1, and not
the overloading part? At least overloading is not in the init-function.
Overloading is not done in the init function, because that would be too
late (the 'wrong' node is already instantiated).
Internally, the getNode() method determines if there is an overloader
set for a specific node, and instantiates that node instead of the
original one. The new one can be a derived class of the original, but it
might as well be a completely different node. Here's an example of an
overloader.
<?php
// replace all occurrences of customer with my own specialised
// version:
$overloaders["customer"] = "myextensions.mycustomer";
class mod_myextensions extends atkModule
{
}
?>
This goes in module.inc. Then, in class.mycustomer.inc, you can
implement a new node that will be used instead of the default
customer node.
The most common thing to do is to extend the original class,
like this:
<?php
class mycustomer extends customer
{
function mycustomer()
{
$this->customer();
$this->setSecurityAlias("customer");
}
// Override some default functionality..
function initial_values()
{
$originalvalues = parent::initial_values();
// Most of our customers come from NL
$originalvalues["country"] = "NL";
return $originalvalues;
}
}
?>
Some explanations:
- The setSecurityAlias makes the new node equal to the original in terms
of accessrights. If you don't do this, mycustomer and customer use
separate security rights.
- with parent:: you can call base class functionality. If you wouldn't
do this, you would 'miss' the original initial values.
This is actually Pizza Guide 3 stuff, but since that seems to be a
never-ending story, I'll put some things on the mailinglist every now
and then.
Greetings,
Ivo
--
Ivo Jansch <ivo dot
ibuildings.nl BV - information technology
http://www.ibuildings.nl