无论条件匹配与否,返回相同结果的计数查询

Count query returning the same result wheather condition matches or not

我是 cakephp 3 的新手。2.I 根据 cakephp 的书使用了一些查询,但我没有得到有效的 result.I 已经发布了我想要的代码 below.Here使用某些 condition.But 计算数据库中的某些记录,无论记录是否存在,它每次都会返回 1。

  $query = $this->Users->find('all')
                    ->where(['Users.email' => $user->email]);
            $emaildata = $query->select(['count' => $query->func()->count('*')]);
            echo $conter = count($emaildata);//alaways returns 1

请告诉我,我做错了什么吗?提前谢谢你。

试试这个

echo $counter = $emaildata->count();exit;