QF registerRule with methods
| From: | Thomas Buedinger | Date: | Thu, 26 Feb 2004 11:43:13 +0000 |
| Subject: | QF registerRule with methods | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-10956@lists.php.net to get a copy of this message | ||
Hello,
a little problem with a 'callback' rule using registerRule.
For database access we had written a class with methods wich worked very well. Also registering them as rules worked fine. Quick form uses the syntax calling methods directly in the following way Class::method().
Now we have the case where we need to inherit one class using some methods from the base class as callback methods. But using the below mentioned syntax we obtain a fatal error "Call to a member function on a non-object in ...".
# Usual way using methods as callback rule:
$form->registerRule('rule_name', 'callback', 'method', 'class');
$form->addRule('formfield', 'Message', 'rule_name', 'some_param');
# is similar to:
class::method('formfield_value', 'some_param');
For making inheritance work, we need a call to a method of an instance of our class wich extends the base class. Testing something like the following:
# This works without any error.
# Inheritance works. Return values true/false work.
$obj = new class();
$obj->method('formfield_value', 'some_param');
Now the questions. Does anyone know how to use instances in registering rules? How is the right syntax? I browsed the documentation several times trying something like:
$obj = new class();
$form->registerRule('rule_name', 'callback', $obj->method );
or
$form->registerRule('rule_name', 'callback', $obj->method, $obj );
or
$form->registerRule('rule_name', 'callback', $obj->method, 'class' );
or
$form->registerRule('rule_name', 'callback', $obj->method, 'file_to_class' );
but none of them works.
Thank you
Thomas