Welcome Guest, Not a member yet? Register   Sign In
$this->db->delete() does not work
#1

[eluser][email protected][/eluser]
post_model.php
Code:
public function delete_post() {
  $this->db->where('pos_id',$this->uri->segment(3));
  $this->db->delete('post');

}

post.php
Code:
<?php
class Post extends CI_Controller {

public function __construct()
{
  parent::__construct();
  $this->load->model('post_model');

}//__construct() END

public function delete() {
  $this->post_model->delete_post();
  
  $this->index();
  
  
  /*$example_id = $this->uri->segment(3);
  $this->db->where(“example_id”, $example_id);
  $this->db->delete(“examples”);
  redirect(‘example’);*/
  
}//delete() END

index.php

Code:
<?php foreach ($post as $post_item): ?>

    <h2>&lt;?php echo $post_item['pos_title'] ?&gt;</h2>
    <div id="main">
        &lt;?php echo $post_item['pos_desc'] ?&gt;
    </div>
    <p><a href="post/&lt;?php echo $post_item['pos_slug'] ?&gt;">View Post</a></p>
<h2>=========================Below is Delete Title for========================= </h2>
    <h2>
  
    &lt;?php
$del_id=$post_item['pos_id'];
$del_ptitle=$post_item['pos_title'];
echo anchor("post/delete/$del_id",$del_ptitle) ;?&gt;
    </h2>
    <h2>=========================ABOVE is Delete Title for========================= </h2>
&lt;?php endforeach ?&gt;


I have been just struggled to understand it like 5 hours straight...
its just keep showing 404 page not found, while all the functions seem valid!

What is the mistake here, can anyone point out for me? Will be really appreciated!!!!
#2

[eluser]masrodjie[/eluser]
Please try using the following code:
post_model.php
Code:
public function delete_post($pos_id) {
  $this->db->where('pos_id',$pos_id);
  $this->db->delete('post');

}

post.php
Code:
public function delete($pos_id) {
  $this->post_model->delete_post($pos_id);
  $this->index();
}

index.php

Code:
&lt;?php foreach ($post as $post_item): ?&gt;

    <h2>&lt;?php echo $post_item['pos_title'] ?&gt;</h2>
    <div id="main">
        &lt;?php echo $post_item['pos_desc'] ?&gt;
    </div>
    <p><a href="post/&lt;?php echo $post_item['pos_slug'] ?&gt;">View Post</a></p>
<h2>=========================Below is Delete Title for========================= </h2>
    <h2>
  
    &lt;?php
$del_id=$post_item['pos_id'];
$del_ptitle=$post_item['pos_title'];
echo anchor("post/delete/$del_id",$del_ptitle) ;?&gt;
    </h2>
    <h2>=========================ABOVE is Delete Title for========================= </h2>
&lt;?php endforeach ?&gt;
#3

[eluser][email protected][/eluser]
[quote author="masrodjie" date="1371141672"]Please try using the following code:
post_model.php
Code:
public function delete_post($pos_id) {
  $this->db->where('pos_id',$pos_id);
  $this->db->delete('post');

}

post.php
Code:
public function delete($pos_id) {
  $this->post_model->delete_post($pos_id);
  $this->index();
}

index.php

Code:
&lt;?php foreach ($post as $post_item): ?&gt;

    <h2>&lt;?php echo $post_item['pos_title'] ?&gt;</h2>
    <div id="main">
        &lt;?php echo $post_item['pos_desc'] ?&gt;
    </div>
    <p><a href="post/&lt;?php echo $post_item['pos_slug'] ?&gt;">View Post</a></p>
<h2>=========================Below is Delete Title for========================= </h2>
    <h2>
  
    &lt;?php
$del_id=$post_item['pos_id'];
$del_ptitle=$post_item['pos_title'];
echo anchor("post/delete/$del_id",$del_ptitle) ;?&gt;
    </h2>
    <h2>=========================ABOVE is Delete Title for========================= </h2>
&lt;?php endforeach ?&gt;
[/quote]

Its not working still, 404 page not found still appears.

Could you tell me how to trouble shoot this in this case? I am so frustrated lol
#4

[eluser][email protected][/eluser]
I feel like there is something wrong with the fact that post/delete fucntion is not even triggered after click that url in view...

What could be the issue?

#5

[eluser]masrodjie[/eluser]
What's the URL generated for that anchor function? I am curious $del_id variable didn't give output
#6

[eluser][email protected][/eluser]
[quote author="masrodjie" date="1371169069"]What's the URL generated for that anchor function? I am curious $del_id variable didn't give output[/quote]

The url is mysite/post/delete/1
if the post deleting script I clicked is related to post id = 1.

Its for some reason, the delete() in controller is not running, and I do not know what could be wrong.

Thanks
#7

[eluser][email protected][/eluser]
RESOLVED, its all about ROUTING

Code:
$route['post/delete/(:any)'] = 'post/delete/$1';

Its perfectly resolved Smile

enjoy guys!

Vote up if you like it~ XD




Theme © iAndrew 2016 - Forum software by © MyBB