Tip: Bundling Custom Components

Here is a nice way to bundle your stuff up. I like it because it makes it easy to share methods between controllers and get rid of code duplication.

I namespaced all my custom components so I don't get them confused with a Model name in the future.

    $di->setShared('component', function() {
        $obj = new stdClass();
        $obj->menu = new \Component\Menu();
        $obj->helper = new \Component\Helper();
        $obj->user = new \Component\User();
        return $obj;
    });

You can access through:

php$this->component->helper->method(123);

or

php{{ component.helper.method(123) }}



83.2k

Nice tip!

Very useful, thanks :) Anybody knows if Is there any way to make autocomplete for this for phpStorm?

Nice tip, You can share on http://phalcontip.com