关于method not exist:think\db\Query->render错误解决方法

 {volist name="Teachers" id="Teachers" key="key"}
            <tr>
                    <td>{$key}td>
                <td>{$Teachers->getData('name')}td>
                <td>{eq name='$Teachers->getData("sex")' value='0'}男{else /}女{/eq}td>
                <td>{$Teachers->getData('email')}td>
                <td>{$Teachers->getData('username')}td>
                <td><a href="{:url('edit?id='.$Teachers->getData('id'))}">编辑  a>
                <a href="{:url('delete?id='.$Teachers->getData('id'))}">删除a>td>
            tr>
        {/volist}
                table>
                当前页总条数{$Teachers->count()}
                {$Teachers->render()}
       div>

html

 

public function index()
    {
        try{
        $pagesize = 10;
        $Teacher = new Teacher;
        //$Teachers = $Teacher->select();
        $Teachers = $Teacher->paginate($pagesize);
       // $teacher = $Teachers[0];
        //var_dump($teacher->getData());
        //echo '
'; //echo $teacher->getData('name'); //echo '
'; //return $teacher->getData('name');
$this->assign('Teachers',$Teachers);//像视图传递数据 //取回打包后的数据 $htmls = $this->fetch(); //将数据返回给用户 return $htmls; }catch(\think\Exception\httpResponseException $e){ throw $e; }catch(\Exception $e){ return $e->getMessage(); } }

PHP 

 

最开始是上面那样的方法  

 

解决方案:

 <div class="col-md-12">
            <hr />
            <a href="{:url('add')}" class="btn btn-primary"><i class="glyphicon glyphicon-plus">i> 增加a>
            <hr />
            <table class="table table-hover table-bordered">
                <tr class="info">
                    <th>序号th>
                    <th>姓名th>
                    <th>性别th>
                    <th>邮箱th>
                    <th>用户名th>
                    <th>操作th>
                tr>
        {volist name="Teachers" id="Teachers" key="key"}
            <tr>
                    <td>{$key}td>
                <td>{$Teachers->getData('name')}td>
                <td>{eq name='$Teachers->getData("sex")' value='0'}男{else /}女{/eq}td>
                <td>{$Teachers->getData('email')}td>
                <td>{$Teachers->getData('username')}td>
                <td><a href="{:url('edit?id='.$Teachers->getData('id'))}">编辑  a>
                <a href="{:url('delete?id='.$Teachers->getData('id'))}">删除a>td>
            tr>
        {/volist}
                table>
                当前页总条数{$Teachers->count()}
                {$page}
       div>

PHP 

public function index()
    {
        try{
        $pagesize = 10;
        $Teacher = new Teacher;
        //$Teachers = $Teacher->select();
        $Teachers = $Teacher->paginate($pagesize);
        $page = $Teachers->render(); 
    //调用render()方法 新添加的这里
// $teacher = $Teachers[0]; //var_dump($teacher->getData()); //echo '
'; //echo $teacher->getData('name'); //echo '
'; //return $teacher->getData('name');
$this->assign('Teachers',$Teachers);//像视图传递数据 $this->assign('page',$page);//这里要重新传递一下 $htmls = $this->fetch(); //将数据返回给用户 return $htmls; }catch(\think\Exception\httpResponseException $e){ throw $e; }catch(\Exception $e){ return $e->getMessage(); } }//千锋PHP-PHP培训的实力派

 

转载于:https://www.cnblogs.com/gaohj/p/6942282.html

你可能感兴趣的:(关于method not exist:think\db\Query->render错误解决方法)