0
**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>
數據正確地插入,但查看沒有顯示數據庫字段這意味着模型文件功能(功能emp_getall())奧林控制文件(功能GETALL())沒有工作給我該解決方案,其中錯誤在此代碼...查看從模型和控制器笨
不能正常工作..同樣得到空白屏幕 – Gaurav
兄弟控制器中的print_r你得到記錄或不在你的視圖中傳遞數據後檢查 –
hothi jimit bro我在codeigniter中使用newbe,但它不工作沒有得到任何值 – Gaurav