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.