繁体   English   中英

为什么我的PHP脚本无法在html中使用? (我使用codeigniter框架)

[英]Why my PHP script doesn't work in my html ? (i use codeigniter framework)

我将php脚本放入html (我使用codeigniter ),但是当我显示在localhost时,我的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');
        }
    }

我的控制器中的脚本不正确,之前:

公共功能category_edit(){

$id = $this->input->post('id'); 

它应该是 :

公共职能类别_编辑($ id)

现在我所有的脚本都在工作! 谢谢你们,特别是兄弟@RajendraSingh!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM