Php 如何创建停用和激活模块的动态方法
我正在开发一个系统。在我的系统中,有称为事件和公告的模块,这两个模块都有停用和激活下拉按钮。为了减少方法的冗余,我想为此创建一个动态方法 但有困难的是,这是从哪个身份证来的?是从活动还是公告?我知道你得走一条路,我已经走了 问题:如何确定ID是否用于事件/公告 注意:我的模式Php 如何创建停用和激活模块的动态方法,php,codeigniter,Php,Codeigniter,我正在开发一个系统。在我的系统中,有称为事件和公告的模块,这两个模块都有停用和激活下拉按钮。为了减少方法的冗余,我想为此创建一个动态方法 但有困难的是,这是从哪个身份证来的?是从活动还是公告?我知道你得走一条路,我已经走了 问题:如何确定ID是否用于事件/公告 注意:我的模式 Event table id event_title event_description event_date Announcement table id announcement_title announcement_
Event table
id
event_title
event_description
event_date
Announcement table
id
announcement_title
announcement_description
announcement_date
在我的控制器中,我使用参数将其传递给我的模型,使其成为动态的。我的参数顺序:表、数据、条件
控制器
看法
模型
如果可能,将您的计划更改为:
One table
id
kind
title
description
date
例如,kind=1可以是event,kind=2可以是announcement,并通过查询中的where kind=1子句返回所需的值id
public function deactivate($table = '',$id = '')
{
$where = array('id' => $id);
$update_status = array(
'status' => 'Inactive'
);
//$this->Crud_model->update($table,$update_status,$where);
//redirect('administrator/event/');
}
public function activate($table = '',$id = '')
{
$where = array('id' => $id);
$update_status = array(
'status' => 'Active'
);
//$this->Crud_model->update($table,$update_status,$where);
//redirect('administrator/branch/'. $session_location);
}
在html下拉列表中更改锚定标记的href:
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<?php if($row->status == 'Active'){?>
<a class="dropdown-item" href="<?= base_url().'administrator/deactivate/{event/announcement}'. $row->id?>">Deactivate</a>
<?php } else { ?>
<a class="dropdown-item" href="<?= base_url().'administrator/activate/{event/announcement}'. $row->id?>">Activate</a>
<?php }?>
<a class="dropdown-item" href="<?= base_url().'administrator/delete/'. $row->id?>">Delete</a>
</div>
您的问题很难理解,您想要实现什么,模式如何与路由相关,两个模式表如何链接?公告是否链接到事件等。请尝试重新表述您的问题,以便您不扩展模型以指定其模式?你只是在使用模型本身并给它指定一张表?如果是这样,您应该将类型/表与之一起存储,并在需要了解类型时读取该变量。仅传递ID不足以标识您的架构。@vickel I仅显示我的2个表的列。这两个表之间没有联系。@Hek mat你有什么建议吗?哇,我不知道你可以在路由中使用两个参数
public function update($table,$data,$where=""){
if($where!="") {
$this->db->where($where);
}
$result = $this->db->update($table,$data);
if ($result) {
return TRUE;
}else{
return FALSE;
}
}
One table
id
kind
title
description
date
public function deactivate($table = '',$id = '')
{
$where = array('id' => $id);
$update_status = array(
'status' => 'Inactive'
);
//$this->Crud_model->update($table,$update_status,$where);
//redirect('administrator/event/');
}
public function activate($table = '',$id = '')
{
$where = array('id' => $id);
$update_status = array(
'status' => 'Active'
);
//$this->Crud_model->update($table,$update_status,$where);
//redirect('administrator/branch/'. $session_location);
}
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<?php if($row->status == 'Active'){?>
<a class="dropdown-item" href="<?= base_url().'administrator/deactivate/{event/announcement}'. $row->id?>">Deactivate</a>
<?php } else { ?>
<a class="dropdown-item" href="<?= base_url().'administrator/activate/{event/announcement}'. $row->id?>">Activate</a>
<?php }?>
<a class="dropdown-item" href="<?= base_url().'administrator/delete/'. $row->id?>">Delete</a>
</div>
$route['admnistrator/deactivate/(:any)/(:any)'] = 'administrator/deactivate/$1/$2';
$route['admnistrator/activate/(:any)/(:any)'] = 'administrator/activate/$1/$2';