Search code examples
ajaxcakephp-3.xinstallation-path

How i find out installation path on Cakephp 3


I have a Cakephp installation on a local wamp in:

c:\wwww\appname

and I have a countdown script in a view:

<script type="text/javascript">
$(document).ready(function()
{   
    var austDay = new Date();
    austDay = new Date(<?= $nextclaimtime * 1000;?>);
    $("#countdown").countdown({until: austDay, format: 'HMS', expiryUrl: "/users/add"});
});
</script>

If i specify /users/add in the expiryUrl everything works in live enviroment but in my local environment it doesn't work because the app is installed under appname.

What is the correct way to change the code so the Ajax call works in both encironments?


Solution

  • The correct way would be to use the router to generate the URL, which would create a URL with respect to the base path/URL.

    <?php $url = \Cake\Routing\Router::url(['controller' => 'Users', 'action' => 'add']); ?>
    
    var expiryUrl = <?= json_encode($url) ?>;
    $("#countdown").countdown({until: austDay, format: 'HMS', expiryUrl: expiryUrl});
    

    See also