Home  >  Article  >  Backend Development  >  thinkphp使用tp框架中使用空操作和空方法,不能定位到_empty()

thinkphp使用tp框架中使用空操作和空方法,不能定位到_empty()

WBOY
WBOYOriginal
2016-06-06 20:28:111775browse

namespace Home\Controller;
use Think\Controller;
class EmptyController extends Controller{

<code>public function _empty() {
    $this->show('404');
}</code>

}
定义了一个空操作和空方法,不存在的空操作和空方法都能走到EmptyController ,
但是已存在的类下面写一个不存在的方法就提示非法操作了。

在每个类下面都写一个_empty()肯定是不现实的,这个控制器放的位置不对吗?
thinkphp使用tp框架中使用空操作和空方法,不能定位到_empty()

thinkphp使用tp框架中使用空操作和空方法,不能定位到_empty()

回复内容:

namespace Home\Controller;
use Think\Controller;
class EmptyController extends Controller{

<code>public function _empty() {
    $this->show('404');
}</code>

}
定义了一个空操作和空方法,不存在的空操作和空方法都能走到EmptyController ,
但是已存在的类下面写一个不存在的方法就提示非法操作了。

在每个类下面都写一个_empty()肯定是不现实的,这个控制器放的位置不对吗?
thinkphp使用tp框架中使用空操作和空方法,不能定位到_empty()

thinkphp使用tp框架中使用空操作和空方法,不能定位到_empty()

你写的有问题,应该是把你的_empty方法写到请求的controller里面,而不是空控制器里面。

就算是要写到空控制器里面,也不是你这样的写法,具体看官方文档:空控制器

如果不想每个类下面都有一个_empty方法,可以写一个BaseController 继承Controller,把_empty方法写到这个里面,你的其他控制器继承这个BaseController就可以了

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