**Controller file i have form_ctrl.php and code given below**
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class form_ctrl extends CI_Controller {
public function index()
{
//$this->load->view('welcome_message');
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->load->model('data_model');
//$this->form_validation->set_rules('name', 'Username', 'required');
$this->form_validation->set_rules('name', 'name','required|min_length[5]|max_length[12]');
$this->form_validation->set_rules('pass', 'Password', 'required',
array('required' => 'You must provide a %s.')
);
$this->form_validation->set_rules('email', 'Email', 'required');
$this->form_validation->set_rules('mobile', 'Mobile', 'required');
$this->form_validation->set_rules('address', 'Address','required|min_length[5]');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('table');
}
else
{
$this->load->view('results');
$name=$this->input->post('name');
$pass=$this->input->post('pass');
$email=$this->input->post('email');
$mobile=$this->input->post('mobile');
$address=$this->input->post('address');
$data = array(
'name' =>$name ,
'pass' => $pass,
'email' => $email,
'mobile' => $mobile,
'address' => $address
);
$this->data_model->insert_fun('form', $data);
}
}
function GetAll()
{
$this->load->model('emp_model');
$data['query']=$this->emp_model->emp_getall();
$this->load->view('emp_viewall',$data);
}
}
**model file i have data_model.php**
<?php
class data_model extends CI_Model {
function __construct() {
parent::__construct ();
}
public function insert_fun($tableName,$data){
return $this->db->insert($tableName, $data);
}
function emp_getall()
{
$this->load->database();
$query=$this->db->get('form');
return $query->result();
}
}
?>
view file i have results.php
<html>
<head>
<title>My Form</title>
</head>
<body>
<table width="100%" border="1">
<tr>
<td>Name</td>
<td>Email</td>
<td>Mobile</td>
<td>Address</td>
<td>Action</td>
</tr>
<?php
foreach($query as $row)
{
print_r($row);exit;
}
?>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</body>
</html>
数据正确插入但视图未显示数据库字段,这意味着IN模型文件函数(函数emp_getall())或控制器文件(函数GetAll())不起作用给我解决方案,其中此代码中的错误...
答案 0 :(得分:0)
function GetAll()
{
$this->load->model('emp_model');
$data['query']=$this->emp_model->emp_getall();
$this->load->view('results',$data);
}
你错误的查看电话检查这个
答案 1 :(得分:0)
<html> <head>
<title>My Form</title>
</head>
<body>
<table width="100%" border="1">
<tr>
<td>Name</td>
<td>Email</td>
<td>Mobile</td>
<td>Address</td>
<td>Action</td>
</tr>
<?php
foreach($query as $row) : ?>
<tr>
<td><?php echo $row->name;?></td>
<td><?php echo $row->email;?></td>
<td><?php echo $row->mobile;?></td>
<td><?php echo $row->address;?></td>
<td><?php echo $row->action;?></td>
</tr>
</table>
<?php endforeach ?>
</body>
</html>
尝试一次.............