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

Beginner question about volt and controllers

Hi,

I just started with Phalcon and coding and I am stuck with a little problem. I am trying to count objects in my view but I am unable to do so, so I ask for help here.

Basically I have 3 models : Series, Episodes and Subtitles.

Relations are as follow :

Series :

$this->hasMany('id', 'Episodes', 'series_id', array('alias' => 'Episodes'));

Episodes:

$this->hasMany('id', 'Subtitles', 'episodes_id', array('alias' => 'Subtitles'));
$this->belongsTo('series_id', 'Series', 'id', array('alias' => 'Series'));

Subtitles :

$this->belongsTo('episodes_id', 'Episodes', 'id', array('alias' => 'Episodes'));

In my SeriesController :

        $series = Series::find();
        $this->view->series = $series;

Then in the view I display series episodes like this :

{% for serie in series %}
                            {% for episode in serie.Episodes %}
                                {{ episode.title }}
                            {% endfor %}
{% endfor %}

What I want is episode count per serie. I am unable to find a way to do so.

Thanks for your help.



853

First of all, thanks for your quick answer and post edition, this is really readable that way. I will do that next time.

Also, one more question about this. Would that work also for subtitles ? :

{{ serie.Episodes.Subtitles.count() }}