4 ms·
I started using functions widely in an MVc framework. It began when Rails was released, and I thought, how could I copy the "helper" mechanism in a way that mak
by ericingram 15y ago
I started using functions widely in an MVc framework. It began when Rails was released, and I thought, how could I copy the "helper" mechanism in a way that makes sense for PHP?
My answer was to use plain functions as helpers, at first because they could easily become Smarty modifiers, and later realized the function-only pattern worked really well across the whole app.
I write code like this...
# file: helpers/say_hello.php
function say_hello ($params)
{
$to = $params['to'] ?: $params;
return "Hello, {$to}!";
}
Which is auto loaded by the framework and usable like this:
(PHP):
echo say_hello('World');
(Smarty):
{say_hello to="World"}
- ericingram 15y agoNote: I purposely called it MVc vs. MVC. The controller is minimized in favor of native REST access to models/resources. If anyone is curious about this, I'll be writing about the new convention soon.