我将php
脚本放入了html
(我使用codeigniter
)中,但是当我出现在本地主机时,我的php
脚本会删除所有标记。
我想在输入文本框中输入用于编辑/更新的内容,并在文本框中显示以前的文本。但是,当我使用php
脚本时,本地主机中缺少标记php中的元素(输入表单和按钮)。
<form method="post" action="<?php echo base_url('dashboard/categories_update'); ?>">
<div class="box-body">
<div class="form-group">
<label>Categories Name</label>
<?php foreach ($kategori as $k) { ?>
<input
type="hidden" name="id"
value="<?php echo base_url().$k->kategori_id; ?>"
>
<input
type="text" name="categories"
value="<?php echo base_url().$k->kategori_nama; ?>" placeholder="Type here. . . "
>
<?php } ?>
</div>
</div>
<div class="box-footer">
<input type="submit" class="btn btn-success" value="update">
</div>
</form>
这是我的控制器代码:
public function categories()
{
$this->load->model('m_data');
$data['kategori'] = $this->m_data->get_data('kategori')->result();
$this->load->view('dashboard/v_header');
$this->load->view('dashboard/v_categories',$data);
$this->load->view('dashboard/v_footer');
}
public function add_categories()
{
$this->load->view('dashboard/v_header');
$this->load->view('dashboard/v_categories_add');
$this->load->view('dashboard/v_footer');
}
public function categories_action()
{
$this->form_validation->set_rules('categories','Categories','required');
if ($this->form_validation->run() !=false) {
$categories = $this->input->post('categories');
$data = array(
'kategori_nama' => $categories,
'kategori_slug' => strtolower(url_title($categories))
);
$this->load->model('m_data');
$this->m_data->insert_data($data,'kategori');
redirect(base_url().'dashboard/categories');
} else {
$this->load->view('dashboard/v_header');
$this->load->view('dashboard/v_categories_add');
$this->load->view('dashboard/v_footer');
}
}
public function categories_edit()
{
$id = $this->input->post('id');
$where = array(
'kategori_id' => $id
);
$this->load->model('m_data');
$data['kategori']= $this->m_data->edit_data($where,'kategori')->result();
$this->load->view('dashboard/v_header');
$this->load->view('dashboard/v_categories_edit',$data);
$this->load->view('dashboard/v_footer');
}
public function categories_update()
{
$this->form_validation->set_rules('categories','Categories','required');
if ($this->form_validation->run() != false) {
$id = $this->input->post('id');
$kategori = $this->input->post('categories');
$where = array(
'kategori_id' => $id
);
$data = array (
'kategori_nama' => $kategori,
'kategori_slug' => strtolower(url_title($kategori))
);
$this->load->model('m_data');
$this->m_data->update_data($where,$data,'kategori');
redirect(base_url().'dashboard/categories');
}
}
答案 0 :(得分:0)
我的控制器中的脚本不正确, 之前:
公共函数category_edit(){
$id = $this->input->post('id');
应该是:
公共函数category_edit($ id)
现在我所有的脚本都在工作!谢谢你们,特别是兄弟@RajendraSingh!