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

Merge string in attributes

If i need create a SELECT with authors ('id' as value and 'lastname' and 'firstname' as name) i use: {{ select('author', author, 'using': ['id', 'lastname']) }}

How i can merge lastname and firstname here? Construction with tilda didn't work: {{ select('author', author, 'using': ['id', 'lastname'~'firstname']) }}

Thanks!



98.9k

Create the query joining the lastname with the firstname:

$this->view->authors = 
       $this->modelsManager->createQuery()
           ->columns('id, CONCAT(lastname, " ", firstname) AS realname')
           ->from('Authors')

Then in the View:

{{ select('author', author, 'using': ['id', 'realname']) }} 

Thanks!

This is solution that i use:

$this->view->authors = $this->modelsManager->createBuilder()
                ->columns(array("id", "CONCAT(lastname, ' ', firstname) AS fullname"))
                ->from('Application\Models\Users')
                ->getQuery()
                ->execute();