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

Writing a Volt select() with optgroups containing different data sources

I'm trying to convert the following HTML code to Volt:

<select name="db_table">
    <optgroup label="Exhibitions">
        // data...
    <optgroup label="Magazines">
        // more data...

But I'm getting a multitide of errors, and I believe it's because I'm structuring my Volt syntax incorrectly.

This is what I have:

{{ select('db_table', ['Exhibitions': [data_one, 'using': ['db_table', 'name']], 'Magazines': [data_two, 'using': ['db_table', 'name']]], 'class': 'form-control') }}

And I'm getting the error:

Catchable fatal error: Object of class Phalcon\Mvc\Model\Resultset\Simple could not be converted to string

The PHP code that is being generated is:

<?= $this->tag->select(['db_table', ['Exhibitions' => [$databases, 'using' => ['db_table', 'event_name']], 'Magazines' => [$databasesR, 'using' => ['form_id', 'form_name']]], 'class' => 'form-control']) ?>

I don't use Volt tags so maybe I'm a bit naive/biased - but if you already have the markup built, what's the advantage of moving to {{ select }} ?

To answer your actual question - your syntax looks way different than the documentation, so I'd look there first.

Philosophically, I think it makes more sense to combine all your disparate data sources into 1 source, then pass that to Volt. If sources change, I think it makes more sense logically to look in the controller to update code, than the view.