How to call a CODEIGNITER method in a TWIG view

Asked

Viewed 73 times

0

Well I’m starting the journey in a project, offered by my School, to gain experience in the area of programming, I got in the middle of it, and I’m having some problems performing simple tasks. So I’m trying to execute a method, which depends on data filled in the view, but I have no idea how to do such an act.

the Code a view:

{% for post in posts %}
            <div class="ui card">
                <div class="content">
                    <span class="right floated star">
                        {{ post['data'] }}
                    </span>
                    <div class="header">{{ post['titulo']|e }}</div>
                    <div class="description">
                        <p>{{ post['descricao']|e }}</p>
                    </div>
                </div>
                <div class="extra content">
                    <span class="left floated like" id="{{ post['id_post'] }}">
                        <i class="like icon"></i>
                        {{ post[''] }} Likes 
//AVISO AQUI EM CIMA É O LOCAL ONDE DEVERIA SER PREECHIDO COM A QUANTIDADE DE CURTIDAS //
                    </span>
                    <div class="right floated author">
                        <img class="ui avatar image" src="{{ post['caminho']|e }}"> {{ "%s %s"|format(post['nome'], post['ultimo_nome']) }}
                    </div>
                </div>
            </div>
 {% endfor %}

The method:

 public function countCurtidas($idpost){
        return ($this->db->query("SELECT COUNT(id_curtida) as curtidas FROM curtida WHERE id_post = $idpost")->row_array());
    }

So to perform this precise method of id_post provided from the view to then fill in with the amount of likes that this post has. Remembering that the view is a template TWIG and I’m using the CODEIGNITER.

1 answer

0

You can call the countCurtidas method within the method that searches for the posts and loads the view and pass this number by pârametro to view as well as the posts, or you can also call ajax to the countCurtidas method, passing the id_post as pârametro.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.