Codeigniter codeinighter,其中字段=来自表单的数据
我正在尝试通过邮政编码搜索匹配供应商: 型号代码: 控制器代码: 显然,忽略打印机和回音,这只是我带来的,我很确定我需要将模型中的$data更改为其他内容,但不确定您的模型中的内容堆是什么:Codeigniter codeinighter,其中字段=来自表单的数据,codeigniter,activerecord,Codeigniter,Activerecord,我正在尝试通过邮政编码搜索匹配供应商: 型号代码: 控制器代码: 显然,忽略打印机和回音,这只是我带来的,我很确定我需要将模型中的$data更改为其他内容,但不确定您的模型中的内容堆是什么: function get_suppliers($data = ''){ i、 e:您没有将$data作为参数包含在模型中: 控制器: 感谢堆,但我如何专门针对邮政编码而不是$data数组?我不能只将数据设置为与来自表单的邮政编码相等的数据。来自表单。当您调用$data作为函数get_suppliers的参
function get_suppliers($data = ''){
i、 e:您没有将$data作为参数包含在模型中:
控制器:
感谢堆,但我如何专门针对邮政编码而不是$data数组?我不能只将数据设置为与来自表单的邮政编码相等的数据。来自表单。当您调用$data作为函数get_suppliers的参数时,变量$data就是您在控制器中传递的变量。此$data变量的作用域仅在此函数内,$data数组的分数仅在控制器内。:至于将邮政编码传递到函数中,您可以使用一个表单并传递发布的数据,您将要求提供邮政编码或$\u GET数据以将邮政编码传递到函数中。谢谢,我想我从来没有想到过这一点。
public function index()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('postcode','Postcode', 'required|numeric|exact_length[4]');
$data = array(
'postcode' => $this->input->post('postcode')
);
if($this->form_validation->run() == FALSE)
{
## reload page ##
$this->load->view('welcome_message');
}
else
{
$this->load->model('site_model');
$this->site_model->add_record($data);
echo("postcode entered");
$data['rows'] = $this->site_model->get_suppliers($data);
print_r($data);
}
}
function get_suppliers($data = ''){
function get_suppliers($postcode = '*') // <-- Capture the postcode
{
$this->db->from('suppliers');
$this->db->where('postcode', $postcode); // <-- pass it in here
$this->db->select('name,type,site,contact,number');
$q = $this->db->get();
if($q->num_rows() > 0)
{
foreach($q->result() as $row)
{
$data[] = $row;
}
return $data;
}
}
public function index()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('postcode','Postcode', 'required|numeric|exact_length[4]');
$data = array(
'postcode' => $this->input->post('postcode')
);
if($this->form_validation->run() == FALSE)
{
## reload page ##
$this->load->view('welcome_message');
}
else
{
$this->load->model('site_model');
$this->site_model->add_record($data);
$data['rows'] = $this->site_model->get_suppliers( $data['postcode'] ); // <-- pass the postcode
echo("postcode entered: " . $data['postcode'] . "<pre>");
print_r($data);
}
}