简体   繁体   中英

How can I get my delete messages function just appear for the user's own messages left on their friends page?

I had been working on this trying the delete message button to work on my own profile page of my site. When I delete a message left by a friend it not only deletes it from the screen but deletes it from the database. The messages in the database have 4 fields: message_id, from, to and message. Here is my profile view that shows how I am deleting messages from my friends:

       if(!empty($messages)){
       foreach($messages as $message):
       $delete = $message['message_id']; 
       //var_dump($message); ?>
      <li><?=$message['from']?> says...: "<?=$message['message']?>"(<?=anchor("home/deleteMsg/$delete", 'delete')?>)</li> //this is where the delete button appears beside messages left
     <?php endforeach?> 
      <?php }else{ ?>
     <?php echo 'No messages left yet !!!'; }?> 

Here is my controller showing the deleteMsg function called:

function deleteMsg($messageid) 
         {

        $this->messages->deleteMsg($messageid);

        redirect('home');

         }

Here is the messages model showing the deleteMsg model itself:

 function deleteMsg($message_id)
      {

        $this->db->where(array('message_id' => $message_id));
        $this->db->delete('messages');

      }

Here is my friendprofile view where I want to implement the delete message command just so the button appears for messages Ive left and I can delete them. The delete button will not appear beside other friends comments on this page:

          <li><?=$message['from']?> says...: "<?=$message['message']?>"</li>      

Now I've tried creating a new delete Message function to no success so far, am I better off doing this than calling the same function? As this didnt work either.

我建议启用CodeIgniter的分析设置,这样您就可以查看在数据库上运行了哪些查询,只需将下面的代码粘贴到控制器中即可:

$this->output->enable_profiler(TRUE);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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