Create link with cakephp inside jquery?

1

How to create a link using the CakePHP conventions inside JQuery?

I'm trying like this but I still can not get it to work.

$(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=/Produto/Detalhar/' + o["Empresa"].id + '>' + 'More' + '</a>';
                }
            }
        ]
    });   
});
    
asked by anonymous 11.10.2015 / 15:43

1 answer

1

Good afternoon,

To use cakephp url paths in javascript is simple, just use the path: -)

 url: "/Empresas/indexAjax.json"

Because the script for the javascript request is cakephp!

In a separate script from .js you can not run php code so it is not working as desired, if at some point you use php code inside javascript you need to have javascript in a .html or .php document EX:

<!DOCTYPE>
<html>
<head>
<script src="/js/jquery.js"></script>
<script>
   $(document).ready(function(){
      alert("o dobro de 5 é <?php echo '10'?>");
   }):
</script>

</head>
<!-- resto do html imaginário -->

I hope I have helped. hug

    
26.10.2015 / 18:46