dongtun2572 2017-05-11 11:22
浏览 39
已采纳

一切都是正确的但是codeigniter显示消息:未定义的变量:数据

Please read the code below

Insertmodel.php

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Insertmodel extends CI_Model {

    public function insertdata($data)
    {
        $this->db->insert('page',$data);
    }
    public function getpagedata()
    {
        //$this->db->select('pname,purl,pub');
        //$this->db->from('page');
        //$this->load->database();

        $getquery = $this->db->get('page');
        return $getquery->result();
    }
}

Pagedatainsert.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Pagedatainsert extends CI_Controller {

    public function insertdata()
    {
        $this->load->helper('date');
        $this->load->model('insertmodel','tblselect');
        $data = array(
            'pname'=>$this->input->post('page-name'),
            'purl'=>$this->input->post('page-url'),
            'pcon'=>$this->input->post('page-content'),
            'pub'=>date('Y-m-d H:i:s')
        );
        $this->tblselect->insertdata($data);
    }
    public function gpdatacon()
    {
        $this->load->model('insertmodel');
        $data['query'] = $this->insertmodel->getpagedata();
        $this->load->view('backend/pages/pages',$data);
    }
}

pages.php (which is under directory backend/pages)

<?php foreach($data as $row){?>
<tr class="odd gradeX">
        <td><?= $row->pname; ?></td>
        <td><?= $row->purl; ?></td>
        <td><?= $row->pub; ?></td>
</tr>    
<?php } ?>

Here an error is occurred which says

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data
Filename: pages/pages.php
Line Number: 73
Backtrace:
File: D:\Ampps\www\customcms\application\views\backend\pages\pages.php
Line: 73
Function: _error_handler
File: D:\Ampps\www\customcms\application\controllers\Backmanage.php
Line: 26
Function: view
File: D:\Ampps\www\customcms\index.php
Line: 316
Function: require_once

My database name is customcms, table name is page.

Made lots of searching on google already but not found so much. Besides, I found a question like this on stackoverflow but that was not so much helpful in my case. I am working for entire day on this problem but it is not getting resolved.

  • 写回答

3条回答 默认 最新

  • doushao1948 2017-05-30 04:37
    关注

    I tried it myself that was the issue with the URL I was calling. I made two pages similar in looks. and accidentally calling the wrong URL that was obvious not working.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看