我有一个页面的 url 作为
在上面的网址中,我有一个表格,我需要在其中填写详细信息并将其保存在数据库中。此页面上的表单是:
<?php
$data = array(
'type'=>'text',
'name'=>'job_title',
'value'=>'Job Title',
'class'=>'form-control');
?>
<?php echo form_input($data); ?>
<?php
$data = array(
'type'=>'submit',
'class'=>'btn',
'name'=>'submit',
'content'=>'Submit!'
);
echo form_button($data);
?>
<?php
echo form_close();
?>
在提交页面时,我希望将其保存在表格中,但同时我也希望携带 url 中的 id/值(在本例中为 1),并希望将其继续直到模型,以便我可以根据此 ID/值在数据库中执行操作。谁能告诉我怎么做
Controller 的当前代码
public function form()
{
$this->form_validation->set_rules('job_title','Full Name','trim|required|min_length[3]');
if($this->form_validation->run() == FALSE)
{
$regdata = array
(
'regerrors' => validation_errors()
);
$this->session->set_flashdata($regdata);
redirect('admin/clients');
}
else
{
if($this->user_model->job())
{
redirect ('admin/client');
}
}
}
当前模型代码//在用户表中,我希望将职位添加到 id 与 url 中的值匹配的那一行,即 1
public function job()
{
$data = array(
'job_title' => $this->input->post('job_title')
);
$insert_data = $this->db->insert('users', $data);
return $insert_data;
}
最佳答案
尝试这样的事情:
$clientId = $this->uri->segment('3'); // will return the third parameter of url
现在将此 $clientId 放入隐藏输入的表单中。现在您可以在表单提交时获取 Controller 函数上的 $clientId。将其传递给模型或相应地使用。
关于php - 从 url 中获取值并将其传递给 codeigniter 中的另一个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38994594/