Can I nest a function within the controller?
Permalink
I've got a block whose view.php contains a form. Action of the form is a function within controller.php. This function contains a switch() and there is a good chunk of code that is the same for each case within the switch. So, I thought it'd be handy to just put all of that code in a function and call it in each case. Can I create a function within my public function?
This is my public function which is the action of my view.php's form:
This may be some silly PHP rule I'm not following...IDK. I've not messed with functions and nesting (whether you should or shouldn't etc).
I was think of something like:
Thoughts?
This is my public function which is the action of my view.php's form:
public function action_create_reminder() { ...bunch of stuff here .... }
This may be some silly PHP rule I'm not following...IDK. I've not messed with functions and nesting (whether you should or shouldn't etc).
I was think of something like:
public function action_create_reminder() { function new_function() { ....code that is the same for every case here ... } ...rest of the code that isn't the same for every case here ... }
Thoughts?
You would do this outside of your action_create_reminder function:-
You call the above using this code, placed within your switch statement
Hope that helps