Codeigniterのビューからモデルにアクセスする方法。CodeIgniterのビューからモデルにアクセスする方法
私は機能を持つモデルを持って、私はUser_controller負荷 ユーザーモデルの$ this - >ロード - >モデル(「Users_model」)に例えばビュー
Codeigniterのビューからモデルにアクセスする方法。CodeIgniterのビューからモデルにアクセスする方法
私は機能を持つモデルを持って、私はUser_controller負荷 ユーザーモデルの$ this - >ロード - >モデル(「Users_model」)に例えばビュー
からこの関数を呼び出す必要があります。
次に、ユーザービューページ$ viewpage = this-> Users_model-> somefunction($ id);
あなたの提案された答えは 'MVC'構造化フレームワークの良い習慣ではありません。 –
まずCIのマニュアルをお読みください:
をあなたはMVC
構造化フレームワークを使用している場合、あなたはそれが動作する方法を次のようする必要があります。お使いのモデルの中に
public function your_controller_function(){
// To load model
$this->load->model ('your_model');
//To Call model function form controller
$data = $this->your_model->model_function($ex_data);
//TO Send data to view
$this->load->view('your_view',['data'=>$data]);
}
:
あなたはコントローラーが必要あなたの視野内
public function model_function($ex_data){
// Your Querys
// user return to send you query result to the controller anything
// Sample Example of query and return
$query = $this->db->select('*')
->where('your_column',$data['column_name'])
->get('your_table');
$your_result = $query->row_array();
if($this->db->affected_rows() > 0){
return your_result;
} else {
return FALSE;
}
}
をあなたが書くことができます。
は<?php
$this->load->model('your_model');
$this->your_model->some_function();
?>
その後、仮定何コントローラーを行うには? –
https://www.codeigniter.com/user_guide/general/models.html#loading-a-model – user4419336
これまでに試したことを追加できますか? –