2017-06-14 138 views
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())没有工作给我该解决方案,其中错误在此代码...查看从模型和控制器笨

回答

0
function GetAll() 
      { 
      $this->load->model('emp_model'); 
       $data['query']=$this->emp_model->emp_getall(); 
       $this->load->view('results',$data); 
      } 

你错了查看呼叫检查该

+0

不能正常工作..同样得到空白屏幕 – Gaurav

+0

兄弟控制器中的print_r你得到记录或不在你的视图中传递数据后检查 –

+0

hothi jimit bro我在codeigniter中使用newbe,但它不工作没有得到任何值 – Gaurav

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> 

试试这一次.............