duankekan9269 2015-04-16 10:11
浏览 42
已采纳

使用CodeIgniter渲染到特定锚点的视图

In order to delete a person from the database, I would like to check its connections with other objects like inventories before deleting then display a bootstrap dialog message within the same page.

Using CodeIgniter, I have a page named "Person's details" that has a link to check these connections like so:

<a class="btn btn-custom" href="person/checkConnections/<?=$ID_Person?>">Delete</a>

In the controller "person", the method "checkConnections" looks like:

public function checkConnections($ID_Person)
{
  $data["strConnections"] = "3 connections with inventories found";
  $this->load->view("person/showdetails", $data)
  // launch the dialog box #deleteMsg
  ???
}

How can I launch the bootstrap dialog box which has an id="deleteMsg" and which is in the "Person's details" page? if it was an html url, the url would look like : http://mywebsite/person/showdetails/134#deleteMsg. But how can I have the same result using the codeIgniter method to render a view?

I can check these connections when loading the page the first time. But it wouldn't be efficient to do it every time since the delete action is rarely used.

  • 写回答

1条回答 默认 最新

  • doudi2431 2015-04-20 06:23
    关注

    You can use ajax to call the delete method and then show the response in a model form like below.

    $('.btn-custom').click(function(e){
            var url = $(this).attr('href');
            $.ajax({
                type: 'GET',
                url: url,
                success: function(rtn)
                { 
                    //load the bootstrap model setting the rtn as html content.
                }
              });
            return false;
        });
    

    the controller should return the html output of your view.

    public function checkConnections($ID_Person)
    {
        $data["strConnections"] = "3 connections with inventories found";
        echo $this->load->view("person/showdetails", $data, true);
    }
    

    note the third parameter true of the view load method, this will return the output of the view.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
  • ¥20 ensp怎么配置让PC1和PC2通讯上
  • ¥50 有没有适合匹配类似图中的运动规律的图像处理算法
  • ¥15 dnat基础问题,本机发出,别人返回的包,不能命中
  • ¥15 请各位帮我看看是哪里出了问题
  • ¥15 vs2019的js智能提示
  • ¥15 关于#开发语言#的问题:FDTD建模问题图中代码没有报错,但是模型却变透明了
  • ¥15 uniapp的h5项目写一个抽奖动画