fuel / core

Fuel PHP Framework - The core of the Fuel v1 framework
http://fuelphp.com
813 stars 345 forks source link

add_model() is_callable will always return true for Model_Crud #837

Closed antitoxic closed 12 years ago

antitoxic commented 12 years ago

Model_Crud based classes have __callStatic which makes add_model() always to return true.

Maybe method_exists can be used?

Maybe add a check whether $method is null and if so don't search for it?

I am currently using a workaround of defining empty set_form_fields methods to my Model_Crud classes.

jschreuder commented 12 years ago

The check being done is just to help prevent mistakes, not to limit possible usage. If we were to change to method_exists() it would expressly disallow using __callStatic() or __call() while returning true when the method actually isn't callable (private/protected). This is why it uses is_callable(): it doesn't limit possible use cases, it only doesn't warn when using a class you shouldn't use for this - but there's only so much coding mistakes we can help prevent, and it's not worth limiting functionality.

antitoxic commented 12 years ago

@jschreuder Please, can Fuel at least check whether whether $method is false.

Otherwise it's not possible to follow the instructions at http://docs.fuelphp.com/classes/validation/validation.html and define custom model validation rules when using Model_Crud based classes without defining empty methods.

jschreuder commented 12 years ago

The docs are lacking there, use $val->add_callabe('Model_Name'); and it'll be added as a source for validation rules without trying to add the fields.