为什么CakePHP在MySQL查询中使用这个方法名而不是返回结果? [英] Why does CakePHP use this method name in a MySQL query rather than return the result?

查看:142
本文介绍了为什么CakePHP在MySQL查询中使用这个方法名而不是返回结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在应用以前的问题,我尝试覆盖了CakePHP的一个内置分页方法:

In applying the answer from a previous question, I tried overriding one of CakePHP's built-in pagination methods:

function paginateCount($conditions = null, $recursive = 0, $extra = array()) {
    if (isset($extra['group'])) {
        for ($i=0; $i<count($extra['group']);$i++) {
            if (strpos(strtolower($extra['group'][$i]),'having')!==false) unset($extra['group'][$i]);
        }
        exit();
    }
    $count = parent::paginateCount($conditions, $recursive, $extra);
    return $count;
}


$ b <的方法名称。显然这不工作,并引发一个错误:

The problem is that this seems to cause Cake to do a MySQL query consisting simply of the name of the method. Obviously this doesn't work and throws an error:


SQL错误:1064:你的SQL语法有一个错误;检查对应于您的MySQL服务器版本的手册在第1行附近的paginateCount使用正确的语法

SQL Error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'paginateCount' at line 1

启用,我可以看到通常会有paginateCount()查询:

Since I have debugging enabled, I can see that where there would normally be the paginateCount() query:

1: SELECT COUNT(*) AS `count` FROM `tournaments` AS `Tournament` WHERE 1 = 1 

我只是得到:

1: paginateCount

我明显误解了PHP的继承运算符。

I've obviously misunderstood PHP's inheritance operators. My function seems to be returning the name of the function it is overriding rather than it's value.

我如何解决这个问题?

推荐答案

这通常发生在CakePHP无法在模型或附加行为中找到方法时。

This usually happens when CakePHP can't find the method in the model or attached behaviors.

然后传递对数据源的调用(希望它有方法,知道该怎么做),这就是为什么你会得到这个错误。

It then passes the call to the datasource (hoping it has the method and knows what to do) and that's why you get this error.

我会检查的东西是他们似乎(是正确的模型中的方法,是由于不正确的文件命名等制作汽车模型)

I would check things are what they seem (is the method in the right model, is Cake making an automodel because of incorrect filenaming, etc.)

这篇关于为什么CakePHP在MySQL查询中使用这个方法名而不是返回结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆