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

Cannot display data

use Phalcon\Mvc\Controller,
    Phalcon\Tag as Tag,
    Phalcon\Mvc\Model,
    Phalcon\Mvc\Model\Resultset,
    Phalcon\Mvc\Dispatcher;

class IndexController extends ControllerBase
{
    public function initialize(){
         $robots = Person::find();

        foreach ($robots as $robot) {
            echo $robot->fname;
        }
    }
}


58.4k

Hey

Why do you very small information ?



43.9k

imho, initialize() should not be used for displaying data !

edited Oct '14

@Duy Thiện, i only want to try first to display small data to test if the code works, but its not working, thats why.

@le51, so u mean i should create a new method that will show the data? what i want to do is i want to display all the data on the index page

i tried

 public function indexAction(){
         $robots = Person::find();

        foreach ($robots as $robot) {
            echo $robot->fname;
        }
    }


98.9k
Accepted
answer

Did you add {{ content() }}/<?php $this->getContent() ?> to your view?

edited Oct '14

@Phalcon,

on my main index.php to where all view are loaded i have

<body>{{ content() }}</body>

do I have to use again

``´ {{ content() }}



in my view / index / index.volt??


98.9k

yes, content() must be placed in every view of the view hierarchy