Skip to content

Comment on The Micro PHP Manifesto's Missing Tenet

Comments

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"}

Note: 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.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.