【问题标题】:Creating a link with CakePHP and JQuery?用 CakePHP 和 JQuery 创建链接?
【发布时间】:2015-10-11 13:30:42
【问题描述】:

我正在尝试在 JQuery 脚本中创建 $this->Html->link。这个链接重定向到我的控制器中的一个动作,问题是我不能这样做。

我该怎么做?

试试这个。

$(document).ready(function() {
    $('#dataTables-example').DataTable({
        "processing": true,
        "serverSide": true,
        "ajax":{
            url: "<?php echo $this->Html->url("/Empresas/indexAjax.json");?>",
            dataSrc:""
        },
        "columns": [
            {"data": "Empresa.id"},
            {"data": "Empresa.nomeFantasia"},
            {"data": "Empresa.cnpj"},
            {"data": "Empresa.telefone1"},
            {"data": "Empresa.telefone2"},
            {"data": "Empresa.celular"},
            {"data": "Empresa.aberto"},
            {"data":null,
                "bSortable": false,
                "render": function(obj) {
                    return "<?php echo $this->Html->link('<i class="glyphicon glyphicon-eye-open"></i>',
                                                        array('action' => 'view', obj["Empresa"].id), 
                                                        array('title'=>'view', 'escape' => false)); ?>";

                    //return '<a href=/Project/Empresas/view/' + o["Empresa"].id + '>' + 'View' + '</a>';
                }
            }
        ]
    });   
});

【问题讨论】:

    标签: php jquery cakephp cakephp-2.0


    【解决方案1】:

    你有错别字。您正在尝试使用错误的运算符获取 $obj["Empresa"] 的属性。你可以用下面的代码做你想做的事。

    <?php $link = $this->Html->link('<i class="glyphicon glyphicon-eye-open"></i>',
                                    ['action' => 'view', $obj["Empresa"]->id], 
                                    ['title'=>'view', 'escapeTitle' => false)]); 
    ?>
    
    return "<? echo $link; ?>";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-16
      • 1970-01-01
      • 2015-08-26
      • 1970-01-01
      相关资源
      最近更新 更多