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

[SOLVED] Using Volt incombination with Hasmany

Hello Everyone,

I'm kinda new to phalconphp, but so far I'm loving it!

My question relates to https://docs.phalcon.io/en/latest/reference/models.html#defining-relationships where models are created that used database relationships to get additional information.

I want to show the related information aswell, but all I can think off to show it in volt is like this:

<div class="row"> {% for Robot in Robots %} <?php
$RobotsParts = $Robot->RobotsParts; foreach($RobotsParts as $RobotsPart){ $Parts = $RobotsParts->Parts; echo "-".$tags->$Parts."<br />"; } ?> </div> {% endfor %} </div> is this the most prefered way or is their an easier one?



573

Hi Again,

I allready figured it out... In order to show the relations you created in the models using hasMany and belongsTo in volt it's rather simple:

<div class="row">
  {% for Robot in Robots %}
  <div class="col-md-4"><h3>{{ Robot.name }}</h3>      
    {% for RobotsParts in Robot.RobotsParts %}
    * {{ RobotsParts.Parts.name }} <br />
    {% endfor %}
  </div>
  {% endfor %}
</div>