2017-06-09 17 views
0

こんにちは私はCodeIgniterに問題があります。 私のクエリは、これは私のコントローラのコードコントローラからモデルへの変数へのアクセス方法

<?php 
class C_Moshakhsat extends CI_Controller{ 
    public function index(){ 
     $data['Todos']=$this->M_Moshakhsat->moshakhsat_list(); 
     $this->load->view('V_Moshakhsat',$data); 
     $product_id = $this->input->get('id', TRUE);  
    } 
} 

?>

であり、これは私のモデルコード

<?php 
class M_Moshakhsat extends CI_Model{ 
    public function moshakhsat_list(){ 

     $query="SELECT customer_name , order_date , saled_product_price , saled_product_quantity, product_name ,saled_product_price*saled_product_quantity as ss FROM customer c ,orders o ,order_detail d , product p WHERE p.produt_id=d.product_id and o.order_id=d.order_id and c.customer_id=o.order_id and o.order_id=product_id"; 
     $res=$this->db->query($query); 
     return $res->result(); 

    } 

     } 

あるID を必要とするので、私はモデル化するために、コントローラから変数にアクセスしたいですか?> URLからIDを取得してクエリに渡したいのですが、わからないのですか?

class C_Moshakhsat extends CI_Controller{ 
    public function index(){ 
     $product_id = $this->input->get('id', TRUE); 
     $data['Todos']=$this->M_Moshakhsat->moshakhsat_list($product_id); 
     $this->load->view('V_Moshakhsat',$data); 

    } 
} 

をモデルに:

+1

'$ this-> input-> get()'は、コントローラ関数の最初の行でなければなりません。結果を引数としてモデルに渡す必要があります。 [Query Builder](https://www.codeigniter.com/userguide3/database/query_builder.html)クラスは、このような簡単なクエリにも役立ちます。 –

答えて

0

ただ、モデルに関数の引数としてIDを送信

public function moshakhsat_list($product_id) 
    { 
     //mysql connections 
    } 

あなたは、これはCIを使用するためのMySQLの注入を避けるために、SQLクエリを解析する必要がありますmysqlクエリーを作成するためのクエリービルダークラス。

+0

あなたはもっとお問い合わせのためのFacebookまたはメールアドレスを持っていますか –

+0

それは私の喜びです[facebook](https://facebook.com/psuzn) –

関連する問題