thinkphp中return $this->fetch的问题 当reture放在foreach循环外面,也就是现在的位置的时候,会报错。如下图。但当return放在foreach语句里面的时候就不会报错,但因为return会结束语句,这也就导致了foreach只执行了一次循环 解决方法 error_reporting(E_ERROR | E_WARNING | E_PARSE);
phpnamespaceapp\index\controller;usethink\Controller;//需要继承think\ControllerclassIndexextendsController{publicfunctionindex(){// 不带任何参数 自动定位当前操作的模板文件// 控制器路径: application\index\controller\Index.php// 模板文件路径: application\index\view\index\index.html//return $this->fetch(...
// 渲染模板输出return$this->fetch(); 需要注意的是,ThinkPHP5 的视图 fetch 方法不会直接渲染输出,只是返回解析后的内容。如果在控制器类返回 视图解析内容的话,渲染输出系统会自动调用 think\Response 类的 send 方法进行渲染输出。 模板定位规则 模板文件目录默认位于模块的 view 目录下面,视图类的 fetch 方法...
$data = Db::name('student')->where('no', $no)->find(); $this->assign('student', $data); return $this->fetch(); } 2.do_edit()实际是执行一个数据库update更新语句 Db::name('student')->where('no', $no)->update($data); 三.测试一下 1.点击编辑 2.查询数据库并返回信息页面 3...
return $this->fetch(); 致命错误: Call to a member function fetch() on null致命错误: Call to a member function fetch() on null protected function fetch($template = '', $vars = [], $replace = [], $config = []) { return $this->view->fetch($template, $vars, $replace, $config...
return $this->fetch(); } public function page() { return $this->fetch(); } } controller控制器中Login.php具体源码如下: <?php namespace app\index\controller; use think\Controller; use think\facade\Request; use app\common\utils\MyRedis; ...
25$where ="username = '$username'"; 26$object =parent::select($this->table, $where); 27if($object && $object->password === md5($password)) { 28returntrue; 29}else{ 30returnfalse; 31} 32} 33publicfunctionshow_profile($username){ 34...
// See the PDO example in this document for more information // Note the `charset=utf8mb4` in the Data Source Name (DSN)$link=newPDO('mysql:host=your-hostname;dbname=your-db;charset=utf8mb4','your-username','your-password',array(PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION,PDO::ATTR...
return $this->fetch('info'); } } 创建插件配置文件 在test目录中创建config.php类文件,插件配置文件可以省略。 <?php return [ 'display' => [ 'title' => '是否显示:', 'type' => 'radio', 'options' => [ '1' => '显示', '0' => '不显示' ], 'value' => '1' ] ]; 创建钩...
return $this->fetch('',[ 'user'=>$res, ]); } } 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 查看了ThinkPHP下的Controller.class.php,,发现报错的位置是: 到这里,才知道问题的所在了。是我在控制器里面的__construct()方法覆盖掉了父类的构造方法。