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

How to echo data from database in phalcon index.phtml file

How to echo data from database in phalcon index.phtml file. Just like the way we do foreach in codeigniter i want to render data in tabular form from my database in phalcom index.phtml . I am beginner with phalcon so please bare with me.



43.9k

Hi,


// in controller 

// fetch some data
$users = User::find();

// pass the data to the view 
$this->view->users = $users;

//in you view file:
    foreach ($users as $user) {
        echo "<tr>";
        echo "<td>" . $user->name . "</td><td>" . $user->birthdate . "</td>";
        echo "</tr>;
    }