Welcome Guest, Not a member yet? Register   Sign In
Extending Helpers
#1

[eluser]Marcel Araujo[/eluser]
I need extending the form helper functions but when I'll make a call the parent function as "form_label" that contains the function "parse_form_attributes" just doesnt work. This doesnt find the parente function!!!

Anyone knows how to help me?

Thanks
#2

[eluser]WanWizard[/eluser]
A helper is just a normal function, not a class method. It therefore doesn't have a parent.

If you extend a helper and add a function with the same name as the original helper, it will replace the original.
#3

[eluser]Marcel Araujo[/eluser]
I understood this perfectly but when I replace the original function, I need access the function "parse_form_attributes" to make this my function works. For example:

I'll override the form_label function and this function needs another function that's "parse_form_attributes"! Do you understand?

I know that a helper is a library functions and doesn't a class to extends methods!
#4

[eluser]mddd[/eluser]
The function is called _parse_form_attributes. Not parse_form_attributes. Did you call the right name?
If you make a MY_form_helper containing your own form_label function, it will have access to all the other functions in form_helper.
#5

[eluser]Phil Sturgeon[/eluser]
Clearly the MY_ helper is called before the main helper, otherwise you would get function override issues. You just need to copy the _parse_form_attributes to your MY_ helper.
#6

[eluser]mddd[/eluser]
As long as the function is not called, I thought the order of function declaration didn't matter?
#7

[eluser]Phil Sturgeon[/eluser]
The order of function declaration matters a lot. Unlike class methods, function declarations do not override.

If you define a function, then define it again, it will not work.

If you call a function that has not been defined, it will not work.

Just put the _parse_form_attributes() in your MY_ helper and see what happens.
#8

[eluser]mddd[/eluser]
Okay, maybe I was unclear. Of course the order matters. That's why in the Helper files there is a check to see if the function is already defined.
But still, as long as the MY_helper contains only function declarations, those declarations should work together with any functions defined in the 'normal' Helper, or even in other helpers. That's why I don't get the problem here.
#9

[eluser]Marcel Araujo[/eluser]
Guys, take a look in form helper and you'll see these are private functions. I forget about this!!! However, I don't wanna copy this private functions already a extending helper.

I'll try and post it here!!!

Thanks
#10

[eluser]Marcel Araujo[/eluser]
I solved my problem and I tell you that method name changed in version from 1.6.2 to 1.7.2 adding a underscore.

Thanks for replies!




Theme © iAndrew 2016 - Forum software by © MyBB