我正在向我的应用程序添加一项功能,用户可以在其中一一删除从朋友那里收到的消息。我在我的消息模型中添加了一个 deleteMessage 函数。然后我在我的家庭控制器的删除函数中调用它。在我的主页视图上,我应该能够通过按“删除”来删除消息。目前没有任何反应。然后,这也会在消息数据库中为他们删除这个特定的内容。db 表包含字段 from、to 和 message。再次感谢您的帮助
我的家庭控制器:
class Home extends CI_Controller
{
function Home()
{
parent::__construct();
$this->load->model('messages');
$this->load->model('friends');
$this->load->model("profiles");
}
function delete($message)
{
$username = $this->session->userdata('username');
$this->messages->deleteMessage($from, $to, $message);
redirect('home');
}
function index()
{
$username = $this->session->userdata('username');
$membername = $this->session->userdata('membername');
$viewData['membername'] = $membername;
$viewData['username'] = $username;
$viewData['following'] = $this->friends->getFollowing($username);
$viewData['followers'] = $this->friends->getFollowers($username);
$viewData['messages'] = $this->messages->getMessages($membername);
$viewData['friends'] = $this->friends->getFriends($username);
$this->load->view('shared/header');
$this->load->view('home/hometitle', $viewData);
$this->load->view('shared/nav');
$this->load->view('home/homeview', $viewData);
$this->load->view('shared/footer');
}
}
消息模型:
class Messages extends CI_Model
{
function Messages()
{
parent::__construct();
}
function deleteMessage($from, $to, $message)
{
$this->db->select('*')->from('messages')->where('from', $from)->where('to', $to)->where('message', $message);
$this->db->delete();
}
}
主页视图:
<h2> Messages</h2>
<ul>
<?php foreach($messages as $message):?>
<li><?=$message['from']?> says...: "<?=$message['message']?>"(<?=anchor("home/delete/$message", 'delete')?>)</li>
<?php endforeach?>
</ul>
</div>