-1

I am trying to build a simple delete function in my project to delete data from a table. I .can't figure out why it is not working. I used the codeigniter user guide to help me out with this. I am getting an error and don't know why. Here is my controller, model and view for the delete:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: stdClass::$id

Model

function delete()
{
    $this->load->database();
    $tables = array('info', 'info2');
    $this->db->where('id', 1);
    $this->db->delete($tables);

}

controller

 function del($tables){


if((int)$tables > 0){
          $this->info_model->delete($tables);
}

$data = $this->info_model->delete();
$data['query'] = $this->result_model->delete();

$this->load->view('info_view',$data);    
 }

view

//this line gives me the error

 <td><?php echo anchor('info_controller/del' . $row->id,'Delete')?> </td>

EDIT

I used this tutorial to make this

http://www.phpeveryday.com/articles/CodeIgniter-Form-Centralizing-$data-P291.html
4

2 回答 2

2

In your controller Load your model like this

$this->load->model('deletion_model');

Then call the method of the deletion_model

$this->deletion_model->delete($id);

Make sure you load the model.

after that i suggest you pass value of id as string.

$this->db->where('id', '1');

OR

use the variable supplied to this function if you are not using static values

$this->db->where('id', $id);

Please read the guide properly

http://ellislab.com/codeigniter/user-guide/database/active_record.html#delete

You can also retrieve the id of the record for deletion by using

$id=$this->uri->segment(3); // depending on which segment the id is
于 2013-03-12T10:39:39.577 回答
-1
  1. I do not see any $row object in your controller, although you use it in your view: $row->id
  2. Your model is not returning anything.
  3. If you delete a specified row, $object->id will cease to exist.
  4. The link in your view it states that you want to show a delete link, but you use that view in the controller that deals with the actual delete action.

Edit: Because you try to iterate in your view through query results, $data['query'] from your controller should point to a select statement.

于 2013-03-12T10:36:48.237 回答