1

コントローラーでモデルのインデックス関数を使用するにはどうすればよいですか??

codeigniter ユーザーガイドに従って、使用できることがわかっています

$this->name_of_model->function_of_model();    

コントローラーで。リダイレクトでは、使用できます

redirect('controller_name/function_name');    

コントローラーでインデックス関数を使用すると、リダイレクトで使用できます

redirect('controller_name');

そのコントローラーにリダイレクトします。このように、どのように使用できますか

$this->name_of_model->function_of_model();

この構文。

ありがとう

4

2 に答える 2

0

Let suppose you are calling a model index in controller index

Class test_controller extends CI_Controller
{
   function index(){

       $this->load->model('model_name');      
       $this->model_name->model_index();      

   }
}

Now when ever you redirect to Controller index the model index will be called automatically.

EDITS: How ever , you can use it like this

Class test_controller extends CI_Controller
{
   function index(){

       $query = $this->db->get('my_table');
       $data['query_result'] = $query->result();  

   }
}

And model index is this

function index()
{
  $query = $this->db->get('my_table');
  return $query->result();
}

You should note model index is not called here instaed model has been useless we are doing work without it. So seperating the database interaction is usefull and combining it with controller breaks the MVC pattren.

于 2012-11-01T05:29:59.810 に答える