Home  >  Article  >  Backend Development  >  thinkPHP 我按照手册使用了 一下 ->order()->limit(1) 怎么都不行?

thinkPHP 我按照手册使用了 一下 ->order()->limit(1) 怎么都不行?

WBOY
WBOYOriginal
2016-07-06 13:54:001113browse

下面是代码,有一句没问题,只要加上 排序 和限制,就报错?求教为什么?

<code>$stmt=D('classOne');
$db = $stmt->where("id>10")->select();    //这句完全没有问题,
$db =$stmt->where("id>10")->order('id desc')->limit(1)->select();    //这句完出错了?为什么?
echo '<pre class="brush:php;toolbar:false">';print_r($db);echo '
';
<code>:(
Call to a member function limit() on null
错误位置
FILE: C:\AppServ\www\yb1\yangbins\Home\Controller\CjdController.class.php  LINE: 68
ThinkPHP3.2.3 { Fast & Simple OOP PHP Framework } -- [ WE CAN DO IT JUST THINK ]</code>

以下是原因:
原来我在 classoneModel.class.php 里多了个:

<code> function __call($methodname, $args)
    {
        echo "这里是 class shopModel ,你调用的方法{$methodname},参数: (".implode(" , ",$args).')  不存在....<br>';
    }</code>

为什么我没有 覆盖 limit() 和 desc(),只是覆盖了魔术方法,整个文件就出错了??

回复内容:

下面是代码,有一句没问题,只要加上 排序 和限制,就报错?求教为什么?

<code>$stmt=D('classOne');
$db = $stmt->where("id>10")->select();    //这句完全没有问题,
$db =$stmt->where("id>10")->order('id desc')->limit(1)->select();    //这句完出错了?为什么?
echo '<pre class="brush:php;toolbar:false">';print_r($db);echo '
';
<code>:(
Call to a member function limit() on null
错误位置
FILE: C:\AppServ\www\yb1\yangbins\Home\Controller\CjdController.class.php  LINE: 68
ThinkPHP3.2.3 { Fast & Simple OOP PHP Framework } -- [ WE CAN DO IT JUST THINK ]</code>

以下是原因:
原来我在 classoneModel.class.php 里多了个:

<code> function __call($methodname, $args)
    {
        echo "这里是 class shopModel ,你调用的方法{$methodname},参数: (".implode(" , ",$args).')  不存在....<br>';
    }</code>

为什么我没有 覆盖 limit() 和 desc(),只是覆盖了魔术方法,整个文件就出错了??

这个错误的原因是order()这个方法没有返回Model类本身,在Model代码中这是正确的,看样子是你实例化的classOneModel这个模型里继承覆盖了order()这个方法,并且没有正确的处理它,请检查其中的是不是这么做了。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn