How can I count columns in phalcon volt?

munaz

I'm new to phalcon. I am retrieving data from the blog table with many ways but I think I'm doing same thing again and again like datetime DESC, datetime DESC LIMIT 5, views DESC LIMIT 5, etc. from the same table. Is there an easy way to retrieve data in one query?

I want to count comments in volt for each post. But it shows like: 11 instead of 2. How do I count comments?

 # Blog Controller
 public function indexAction()
 {
   #Data Retrieve
    $bloger = Blogs::find(["order" => "datetime DESC"]);
    $this->view->setVar('blogs', $bloger);
  :Count How Many Post have each User
    $pcount = Blogs::findBybauthor($this->session->get('uname'));
    $this->view->setVar('eachpost',count($pcount));
  :Get Recent Posts
    $latest = Blogs::find(["order" => "datetime DESC limit 5"]);
    $this->view->setVar('recent', $latest);
  :Get Most visited Posts
    $viewer = Blogs::find(["order" => "views DESC limit 5"]);
    $this->view->setVar('views', $viewer);
  :Comments Retrieve
    $coment = Comments::find();
    $this->view->setVar('comented', $coment);
    }

   #[VOLT]

This is my volt tags its not showing as expected. I also use |length but it's not working as expected:

 {% for coment in comented %}
 {% if coment.entry_id === bloger.id %}
 <?php echo(count($coment->entry_id)); ?>
 {% endif %}
 {% endfor %}

How can I achieve that?

munaz
In controller first try to render each posts detail  in view (blog/show)
Here is my controller.php.


public function showfullAction($pid)
{
    $blog = Blogs::findFirstById($pid);
    $gid = $blog->id;
    $data = Blogs::findFirstById($gid);
    $this->view->setVar('detail', $data);
    #Similar Posts
    $similar = Blogs::find(["btitle LIKE :title:","bind"=>["title"=>'%'.$data->btitle.'%'],"order" => "datetime DESC limit 5"]);

    $this->view->setVar('datas', $similar); 
    $this->view->pick('blog/show');
   }

   And finally in my view page (blog/show):

 {% for similar in datas %}
 {{link_to('blog/showfull/'~similar.id,similar.btitle,'class':'cats')}}  <br/>
 {% endfor %}

and now its working as expected!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I count the numbers of rows that a phalcon query returned?

How to convert a variable to int in Phalcon's .volt?

How can I count unique values by columns

how I can count signs columns?

How can I group with multiple columns and count?

phalcon volt bitwise operatios?

How can I use NOT BETWEEN in a query in Phalcon?

How can I count values that can be grouped by another columns in R

Hyperlink does not work on volt in phalcon

How can I count replicate values across columns?

How can I separate two columns of count by group by?

How can I Count the number of columns in a .txt file in VBA

How can I count duplicate rows according to specific columns?

How can I count the number of columns a value has after a Where?

How can i get a count(*) of all the columns in a table? Using PostgreSql

How can I get the count and newest record for each pair of columns?

How can I get the count of the amount of grouped columns as a column?

How can I count the nominal data from multiple columns

How can I count the amount of values in different columns in oracle plsql

How do I do a jQuery toggleClass in Volt?

How do I add a button in ruby volt?

How can I access Phalcon configuration data in an external library?

Can I count multiple columns with Group By?

Autoescape setting for Phalcon's Volt-engine?

How can I groupby a DataFrame at the same time I count the values and put in different columns?

I have a 3.3 Volt PCI ethernet card working on a 5 Volt PCI slot. How is it possible?

How do I uninstall Phalcon?

How to count the total documents in phalcon mongodb collection

how can I count the status