如何从模型获取值到控制器

How to get the value from model to controller

型号

这是我的model.using 上次查询我在模型中获得了值,但我没有在控制器中获得值

class Login_model extends CI_Model {
    function __construct()
    {
        parent::__construct();
    }
    public function email()
    {
        $this->db->select('email');
        $this->db->from('change_password');
        $result=$this->db->get();
        return $result;
    }
}

控制器

class Login extends CI_Controller {
    function __construct()
    {
        parent::__construct();
    }

    function checking()
    {
        $email=$this->input->post('email');
        $this->load->model('login_model');
        $dbemail=$this->login_model->email();
        echo $dbemail;
    }
}

CI 是一个 MVC 框架。因此,您需要从控制器发出命令并从模型中获取数据,并且您需要将它们传递给视图。这是最佳实践

控制器

function checking()
 {
 $email=$this->input->post('email');
 $this->load->model('login_model');
 $data['dbemail']=$this->login_model->email();// assign your value to CI variable  
 $this->load->view('home', $data); //passing your value to view
 }

型号

public function email()
 {
   $query = $this->db->query("SELECT email FROM change_password");
   $result = $query->result_array();
   return $result;
 }

查看

额外知识

  1. 视图将在 View 文件夹/ Ex 下使用视图名称创建 作为 home.php
  2. 您可以使用自己的样式(它也创建为普通 html 页面。)

     foreach ( $dbemail as $new_dbemail )
       {
          echo $new_dbemail['database_field'];//in here you can get your table header. 
         //Ex if your table has name field and you need to sho it you can use $new_dbemail['name'] 
        }