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 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作