Home >Backend Development >PHP Tutorial >I used thinkPHP according to the manual ->order()->limit(1) but nothing works?
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 '';
<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>
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>
Why did I not cover limit() and desc(), but just covered the magic method, and the whole file went wrong??
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 '';
<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>
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>
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 classOneModel
Inheritance overrides in this modelorder()
This method, and it is not handled correctly, please check whether it is done this way.