编辑和删除codeigniter中的问题 [英] Edit and delete issues in codeigniter

查看:174
本文介绍了编辑和删除codeigniter中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了一些步骤,但到现在为止,我的编辑和删除功能无法正常工作。你能帮我一下吗?

I tried some of the steps here, but until now, my edit and delete functions do not work correctly. Can you please help me with it?

首先,我在客户控制器中有这些行:

First, I have these lines in my client controller:

public function edit_job
{

    $this->validateRole('client');
    $this->load->model('job_model');

    $id = $this->uri->segment(3);

    $data['my_preference'] = $this->array_to_select( $this->job_model->get_all_categories(), 'id','name');
    $data['job'] = $this->job_model->get_job($id);
    $this->load->view('client/edit_job', $data);
}

public function delete_job() 
{

    $this->validateRole('client');
    $this->load->model('job_model');

    $id = $this->uri->segment(3);

    $this->job_model->delete_job($id);
    //echo '<script language="javascript">alert("Post successfully deleted.");</script>';
    redirect('client/manage_jobs?message=Job post successfully deleted');

}
}

my job_model

Then, I have these lines in my job_model

function edit_job() 
{
    $data = array(
        'title' => $this->input->post('title'),
        'category_id' => $this->input->post('category_id'),
        'start_date' => date("m-d-Y", strtotime($this->input->post('start_date'))),
        'description' => $this->input->post('description'),
    );
    $this->db->where('id', $this->input->post('id'));
    $this->db->update('job', $data);

}
function delete_job($id) 
{
    $this->db->where('id', $id);
    $this->db->delete('job', $data);
}

目前,添加作业相当不错日期),但编辑和删除不能很好地工作。每当我在我的视图页面中按编辑,它将显示一个完全类似于一个新的add_job页面的页面(所以每当我输入并填写表单,它将被添加为一个新的工作,而不是作为一个特定工作的修订) (我一直在尝试回复原始值之前编辑可以做,但它从来没有工作。在删除作业方面,它显示重定向消息,但每当我检查作业可用,据称删除的作业仍然

Currently, add job works quite well (although I sometimes have problem with the start date), but edit and delete do not work well. Whenever I press edit in my view page, it will show a page exactly similar to a new add_job page (so whenever I type and fill in the form, it will be added as a new job, not as a revision of a particular job) (I've been trying to echo the original values first before editing can be done, but it never worked. In terms of delete job, it does show the redirect message, but whenever I check the jobs available, the supposedly deleted job is still available.

我已经被困在这里相当一段时间了,请帮助我。

I have been stuck here for quite some time now. Please help me..

推荐答案

我认为asp_tags在您的php设置中禁用更改您的代码如下:

I think asp_tags is disable in your php settings. Change your code as following:

<?php echo $this->uri->segment(3, 0); ?>

而不是

<?= $this->uri->segment(3, 0); ?>


和关于删除,您不需要在删除函数中传递第二个参数。请执行以下操作:


and about delete, you don't need to pass second parameter in delete function. So do following:

$this->db->delete('job');

而不是

$this->db->delete('job', $data);

这篇关于编辑和删除codeigniter中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆