Undefined variable (Twig)

Dear Phalcon community,

I'm having some issues with a foreach loop that prints duplicate data.


  public function indexAction()
  $this->view->robots = robots::find();  
  $this->view->robots2 = robots2::find();  


{% for robot in robots  %}
    {% for robot2 in robots2 %}
    <td> robot.name </td>
    <td> robots2.name </td>
    {% endfor %}
{% endfor %}

Is there anyway to do this better? I tried it without the foreach loop but it is needed else i get: Undefined variable.

Thanks in advance,

edited Oct '15

I am not sure what is the problem :/ Can u give us more details what u want to accomplish?

I think u has error in <td> robots2.name </td> - must be robot2. (maybe only in example).

I want to pull data from 2 different tables in the database. It does work when using foreach loops, but i get duplicated data. So i was wondering what the best way is to pull data from 2 different database tables without getting the error Undefined variable and best way to not get duplicated data from volt..

Still didnt get the problem. I never had a issue when use that type of foreach's. Even i have 4 invested foreach without to loose some var, duplicated or undefined variable. So... i do not know how to help you :/ if u give more details about your case, maybe we can find the issue.

Let the force be with u