简体   繁体   English

删除确认短信 php codeigniter

[英]Delete confirmation message in php codeigniter

I am trying to get confirmation message before deleting the data, and also I would like to maintain my data in database while deleting them in frontend.我试图在删除数据之前获取确认消息,并且我还想在前端删除数据的同时在数据库中维护我的数据。 here is my (project) index.php view这是我的(项目)index.php 视图

 <div class="main-sec-contant">
<div class="ProjectsDetails">
    <h2 class="heading">Projects Details</h2>
    <div class="row">
        <div class="col-md-12">
            <table id="table_id" class="display">
                <thead>
                    <tr>
                        <th>Project Name</th>
                        <th>Client Name</th>
                        <th>Company</th>
                        <th>Project Manager</th>
                        <th>Support Staff</th>
                        <th>Status</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                <?php
                foreach($project as $n)
                {
                    ?>
                    <tr>
                        <td><?php echo $n->project_name;?></td>
                        <td><?php echo $n->client_name;?></td>
                        <td><?php echo $n->company;?></td>
                        <td><a class="pro-circle"><img class="img-sm" src="<?php echo site_url('assets/image/man.png');?>"  data-toggle="tooltip" data-placement="bottom" title="<?php echo $n-> project_manager;?>" data-original-title="Click to deactivate the user"></a>&nbsp&nbsp </td>
                        <td><a class="pro-circle"><img class="img-sm" src="<?php echo site_url('assets/image/man.png');?>" data-toggle="tooltip" data-placement="bottom" title="<?php echo $n-> support_staff;?>" data-original-title="Click to deactivate the user"></a>&nbsp&nbsp 
                        <a class="pro-circle"><img class="img-sm" src="<?php echo site_url('assets/image/man.png');?>"></a>&nbsp&nbsp
                      <a class="pro-circle"><img class="img-sm" src="<?php echo site_url('assets/image/man.png');?>"></a></td>
                        <td><span class="icoact"></span> Active</td>
                        <td><a class="edit" href="<?php echo site_url('admin/project/edit/'.$n->id);?>"><i class="fa fa-pencil-square-o" ></i></a>&nbsp&nbsp<a class="delete"  href="<?php echo site_url('admin/project/delete/'.$n->id);?>"><i class="fa fa-trash-o"></i></a></td>
                    </tr>
                    <?php
                }
                ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

Here is my Project.php controller这是我的项目。php controller

public function index ()
{
  $data['company_name'] = $this->project_model->getAllCompanyName();
  $data['project'] = $this->project_model->getProjectDetails();
  $this->load->view('admin/project/index',$data);

}
function delete($id)
 {
   $this->project_model->delete($id); 
   $this->session->set_flashdata ('success','Project Deleted Sucessfully');
   redirect('admin/project/index');

 }

And here is my Project_model.php, delete function这是我的 Project_model.php,删除 function

 function getProjectDetails()
 {
//table  (projects)

 $delete_flag=0;
 $data['project'] = $this->db->get_where('projects',array('delete_flag!='=>$delete_flag))->result_array();

} }

function getById($id)
 {
   return $this->db->get_where('projects',array('id'=>$id))->row();

 }

function delete($id)
 {
  $delete_flag=0;
  $this->db->where('id',$id)->update('projects',array('delete_flag'=>$delete_flag));
    
 }

Right now I am able to delete the data successfully from both frontend and database, I would appreciate if you can help me how I can get the confirmation message, and also maintain my data in database while deleting them from frontend?现在我能够从前端和数据库中成功删除数据,如果你能帮助我如何获得确认消息,并在从前端删除数据的同时在数据库中维护我的数据,我将不胜感激?

Here is the database table这是数据库表

在此处输入图像描述

Delete in Frontend only:仅在前端删除:

Add a boolean Column "delete_flag" to your project database table and update it to TRUE when delete is clicked in frontend.将 boolean 列“delete_flag”添加到项目数据库表中,并在前端单击删除时将其更新为 TRUE。

Then change your load Method in Project model to only get Projects where delete_flag = 0然后将项目 model 中的加载方法更改为仅获取 delete_flag = 0 的项目

Delete Confirmation:删除确认:

Search for Modal Dialog.搜索模态对话框。 You can easily set up a message and confirm button link with a modal Dialog.您可以轻松地设置消息并确认按钮与模态对话框的链接。 Maybe you are even using a Template which already provides it.也许您甚至正在使用已经提供它的模板。

See an example here: https://www.w3schools.com/howto/howto_css_modals.asp请在此处查看示例: https://www.w3schools.com/howto/howto_css_modals.asp

For Data Delete from Frontend only but not from database:-对于仅从前端删除但不从数据库删除的数据:-

You should add a Column name delete_flag int datatype to your project database table and update it to 0 , while deleting the record.您应该将 Column name delete_flag int 数据类型添加到项目数据库表并将其更新为0 ,同时删除记录。

Data Delete Confirmation Alert Message:-数据删除确认提示信息:-

<td><a class="delete"  href="<?php echo site_url('admin/project/delete/'.$n->id);?>"  onclick="return confirm('Are you sure want to Delete this Record?')"><i class="fa fa-trash-o"></i></a></td>

controller Code Project.php:- controller 代码项目.php:-

function delete($id)
{
   $this->project_model->delete($id); 
   $this->session->set_flashdata ('success','Project Deleted Sucessfully');
   redirect('admin/project/index');

}

Model Code Project_model.php:- Model 代码 Project_model.php:-

function getProjectDetails()
{
$delete_flag=0;
   $data['project'] = $this->db->get_where('projects',array('delete_flag!='=>$delete_flag))->result_array();
}


    function delete($id)
    {
          $delete_flag=0;
          $this->db->where('id',$id)->update('projects',array('delete_flag'=>$delete_flag));
        
    }

In Your View:-在您看来:-

Show Only records which have delete_flag!=0 by this query in your getProjectDetails()在您的getProjectDetails()中通过此查询仅显示具有delete_flag!=0的记录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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