Reputation: 1266
I am not quite sure how to achieve passing the relative project root directory to a javascript file. Purpose of having this is to call an ajax function that should use relative paths to the root dir.
However, one ugly method would be to store the dir in the meta fields of the HTML header, but I really want to avoid this.
Any theoretical suggestion?
Are there any kind of Javascript helper in version 3.0?
Upvotes: 0
Views: 53
Reputation: 4469
You can use router class for that
Use below namespace
use Cake\Routing\Router;
Then in your ajax URL you can use below code
url:'<?php echo Router::url(['controller' => 'YourController', 'action' => 'Method']); ?>',
Upvotes: 1