Php 代码点火器删除链接
我有标签和文章表,它们是分开的。我正在尝试删除与文章相关的标签。当用户删除文章时,该文章的标签也将从标签表中删除。我已经创建了下面的模式,但它不起作用。我不明白为什么 物品管理员Php 代码点火器删除链接,php,codeigniter,Php,Codeigniter,我有标签和文章表,它们是分开的。我正在尝试删除与文章相关的标签。当用户删除文章时,该文章的标签也将从标签表中删除。我已经创建了下面的模式,但它不起作用。我不明白为什么 物品管理员 public function delete($id){ $this->article_m->delete($id); } 文章模式 public function delete ($id) { // Delete the article parent::delete($id);
public function delete($id){
$this->article_m->delete($id);
}
文章模式
public function delete ($id)
{
// Delete the article
parent::delete($id);
// Delete tags
$this->load->model('tag_m');
$this->tag_m->delete_article_tags($id);
}
标签型号:
public function delete_article_tags($id){
$this->db->where('content_id', $id);
$this->db->where('content_type', 'article');
$tags = $this->db->get('tags');
foreach ($tags as $tag) {
parent::delete($tag->id);
}
}
public函数删除文章标签($id){
$this->db->where('content\u id',$id);
$this->db->where('content_type','article');
$tags=$this->db->get('tags');
//foreach($tags作为$tag){result()作为$tag){
父项::删除($tag->id);
}
}
另外,检查控制器中是否加载了所有模型。在删除文章之前,您应该删除所有相关信息。否则会破坏数据一致性。您能显示此模型的所有代码吗?此行使用父函数delete,但文章模型的父函数是什么?parent::delete($id);
public function delete_article_tags($id){
$this->db->where('content_id', $id);
$this->db->where('content_type', 'article');
$tags = $this->db->get('tags');
//foreach ($tags as $tag) { <--- Replace this line to:
foreach($tags->result() as $tag) {
parent::delete($tag->id);
}
}