marius
marius

Reputation: 1266

CakePHP passing root dir to javascript

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

Answers (1)

Alimon Karim
Alimon Karim

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

Related Questions