How to count total number of rows of table in Cakephp

cakephp, php, rowcount

Solution

use find('count')

For example:

$total = $this->Article->find('count');

If you want to use a condition in your query, then pass the conditions array, here is a sample code:

$pending = $this->Article->find('count', array('conditions' => array('Article.status' => 'pending')));

Problem

How to count the total number of rows of table and pass it to the variable? For example, I have product table and there are 10 products in it. I want to count all the rows and get the result 10 and pass it to the variable $rowcount. How can I do it?

Original source