Reputation: 4460
I'm trying create a $this->Html->link
inside a JQuery script. This link goes redirect to an action in my controller the problem is that I can not do this.
How could I do this ?
Trying this.
$(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>';
}
}
]
});
});
Upvotes: 0
Views: 159
Reputation: 654
You have typos in this. You're trying to get property of $obj["Empresa"]
with wrong operator. You can do what you want with the code below.
<?php $link = $this->Html->link('<i class="glyphicon glyphicon-eye-open"></i>',
['action' => 'view', $obj["Empresa"]->id],
['title'=>'view', 'escapeTitle' => false)]);
?>
return "<? echo $link; ?>";
Upvotes: 2