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

Phalcon\Assets\Collection need method __toString()

Hi evryone,

I woudlike to minify all js scripts (https://docs.phalcon.io/pl/latest/reference/assets.html) but I'dlike to add js file in views not in controllers. In my layout I use:

        {{ assets
            .collection("out")
            .addJs('//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js', false, false)
            .addJs('//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js', false, false)
        }}

but Phalcon\Assets\Collection doesn't have __toString() method so in console I have:

[Wed, 10 Dec 14 13:24:58 +0100][ERROR] Object of class Phalcon\Assets\Collection could not be converted to string | on line: 29 | in file: /home/****/_apps_common_frontend.volt.php | [4096]

When I use native php, evrythink work fine



3.4k
Accepted
answer

I use the following in head section and it works

{% do assets.collection('headJs').addJs('js/jquery.min.js') %}
{% do assets.collection('headJs').addJs('js/semantic.min.js') %}
{{ assets.outputJs('headJs') }}


12.8k

magic word "do"