Home > Backend Development > PHP Tutorial > I used thinkPHP according to the manual ->order()->limit(1) but nothing works?

I used thinkPHP according to the manual ->order()->limit(1) but nothing works?

WBOY
Release: 2016-07-06 13:54:00
Original
1188 people have browsed it

The following is the code. There is a sentence that is fine. As long as you add sorting and restrictions, an error will be reported? Please tell me why?

<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 '
';
Copy after login
Copy after login
<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>
Copy after login
Copy after login

The following is the reason:
It turns out that I have an extra one in classoneModel.class.php:

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

Why did I not cover limit() and desc(), but just covered the magic method, and the whole file went wrong??

Reply content:

The following is the code. There is a sentence that is fine. As long as you add sorting and restrictions, an error will be reported? Please tell me why?

<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 '
';
Copy after login
Copy after login
<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>
Copy after login
Copy after login

The following is the reason:
It turns out that I have an extra one in classoneModel.class.php:

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

Why did I not cover limit() and desc(), but just covered the magic method, and the whole file went wrong??

The reason for this error is that order() this method does not return the Model class itself. This is correct in the Model code. It seems that you instantiated it classOneModelInheritance overrides in this modelorder()This method, and it is not handled correctly, please check whether it is done this way.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template