Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

Implementing registerActiveRecordMethod

posted by riddla 9 years ago

Hi.

I'm trying to extend a fActiveRecord model with...

class Immobilien2daten extends fActiveRecord implements Iterator
{
    protected function configure()
    {
		fORM::registerActiveRecordMethod($this, 'getCheckboxes', 'Immobilien2daten::getCheckboxes');
    }
    
	public function getCheckboxes($object, &$value, &$old_values, &$related_records, &$cache, $method_name, &$parameters)
    {
    	// [...]
    }
        
    // [...]
}

Trying...

$immo_daten->getCheckboxes();

ends in...

Warning: Missing argument 1 for Immobilien2daten::getCheckboxes(), called in [...]object.php on line 58 and defined in [...]/models/Immobilien2daten.php on line 58

... and so on, the warning comes for all arguments of 'getCheckboxes'.

Any ideas?

Thanking you in anticipation,

Volker

To answer myself:

I registered the method using the same function name,...

fORM::registerActiveRecordMethod($this, 'getCheckboxes', 'Immobilien2daten::_getCheckboxes');

and

public static function _getCheckboxes($object, &$value, &$old_values, &$related_records, &$cache, $method_name, &$parameters)

did the trick.

But I had to change the function to be static. Maybe you could update the docs @ http://flourishlib.com/docs/fORM#AddingMethodstofActiveRecord?

posted by riddla 9 years ago

What is happening here is that you are using functionality intended for creating ORM plugins (such as fORMFile, fORMOrdering, etc) to implement a method in a class. Instead of using the composition functionality, where you can add methods to any class at run-time, just implement the method on the class, like so:

class Immobilien2daten extends fActiveRecord implements Iterator
{
    protected function configure()
    {
    }
    
    public function getCheckboxes()
    {
        // [...]
    }
        
    // [...]
}
posted by wbond 9 years ago