使用db获取参数错误


Use db with get parameters error

我使用许多DB来进行语言响应。

class Category extends CI_Model
{
public function __construct()
{
    parent::__construct();
    $this->lanDB = array(
        "KR" => $this->load->database('KR', TRUE),
        "EN" => $this->load->database('EN', TRUE),
        );                                        
}
public function get(){
    $category = $this->lanDB['KR']->from('Category')->get()->result();
    foreach ($category as $value) {
        $value->list = $this->lanDB['KR']->select('id AS series_id, subject')->from('Series')->
            where('category_id', $value->id)->get()->result();
    }
    return $category;
}
} 

这段代码不错。但是像这样使用get参数而不是'KR'

class Category extends CI_Model
    {
    public function __construct()
    {
        parent::__construct();
        $this->lanDB = array(
            "KR" => $this->load->database('KR', TRUE),
            "EN" => $this->load->database('EN', TRUE),
        );                                        
    }
    public function get(){
        $category = $this->lanDB[$_GET['country']]->from('Category')->get()->result();
        foreach ($category as $value) {
            $value->list = $this->lanDB[$_GET['country']]->select('id AS series_id, subject')->from('Series')->
            where('category_id', $value->id)->get()->result();
        }
        return $category;
    }
} 

class Category extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
        $this->lanDB = array(
            "KR" => $this->load->database('KR', TRUE),
            "EN" => $this->load->database('EN', TRUE),
        );                                        
    }
    public function get(){
        $category = $this->lanDB[$this->input->get('country')]->from('Category')->get()->result();
        foreach ($category as $value) {
            $value->list = $this->lanDB[$this->input->get('country')]->select('id AS series_id, subject')->from('Series')->
            where('category_id', $value->id)->get()->result();
        }
        return $category;
    }
}

这段代码不能运行。

请帮帮我。

你需要像这样从控制器传递参数:

public function controller_function_name() {
  $result = $this->model->get($this->input->get('country'));
  $data = array();
  $data['result'] = $result;
  $this->load->view('view_file_name', $data);
}

And in model:

public function get($country){
$category = $this->lanDB[$country]->from('Category')->get()->result();
foreach ($category as $value) {
    $value->list = $this->lanDB[$country]->select('id AS series_id, subject')->from('Series')->
        where('category_id', $value->id)->get()->result();
}
return $category;
}