We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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



98.9k

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 https://phalcontip.com