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

Passing object with built html code to view

Hello, I am trying to build a html table from database. I found difficilties passing some html and value as object to Volt. Maybe someone has anything to offer?


 $users = User::find();

        foreach ($users as $user) {

            $this->view->name .= '<td>'.$user. '<\td>'->name;

        }


93.7k
Accepted
answer
edited Dec '17

Im not 100% sure what you want to achieve, but maybe this example could help?

// Controller code
$this->view->users = User::find();

// Volt
<table>
    <thead>
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Age</th>
        </tr>
    </thead>    
    <tbody>
        {% for user in users %}
        <tr>
            <td>{{ user.id }}</td>
            <td>{{ user.name }}</td>
            <td>{{ user.age }}</td>
        </tr>
        {% endfor %}
    </tbody> 
</table>

Nikolay, thank you very much. It is exactly what I need.