user1250526
user1250526

Reputation: 309

Codeigniter deleting

I am having fun with codeigniter but having an annoying little problem at the moment though, when trying to delete an item I get ” Message: Undefined property: Site::$url ” my only guess can be that something is not right with the url helper being included? I am autoloading it in the config.

this is my delete function in the model

 function delete_record()
 {
  $this->db->where('id', $this->url->segment(3));
  $this->db->delete('items');

 }  

here I am calling it in the view:

<?php echo $row->subject; ?> <?php echo anchor("site/delete/$row->id","Delete");?> 

this is the controller:

function delete(){
  $this->Site_model->delete_record();
  $this->index();
  }  

and just to make sure I am not doing anything wrong.. this is in autoload in the config:

$autoload['helper'] = array('url', 'form');
$autoload['libraries'] = array('database'); 

Much appreciated for any help!!

Upvotes: 2

Views: 778

Answers (4)

Raham
Raham

Reputation: 4951

What you done is all right just replace the 'url' to 'uri',like this.

$this->url->segment(3) to $this->uri->segment(3) //replace url to uri.

Upvotes: 0

GautamD31
GautamD31

Reputation: 28753

There are two changes u hav to made:

FIRST:

$this->url->segment(3) to $this->uri->segment(3);

SECOND:In the view

<?php echo $row->subject; ?> <?php echo anchor("site/delete/".$row->id,"Delete");?> 

Upvotes: 0

Muhammad Yasin
Muhammad Yasin

Reputation: 418

It must be

$this->uri->segment(3) not $this->url->segment(3) 

Upvotes: 0

Brendan
Brendan

Reputation: 4565

There is no url class.

You want to switch $this->url->segment(3) to $this->uri->segment(3) noting the I instead of the L.

The url helper is for generating site urls, etc. The URI class is an integral part of the CI core so it is always loaded.

URI Class

URL Helper

Upvotes: 1

Related Questions