Amir Rustamzadeh
Amir Rustamzadeh

Reputation: 4528

Using php as external javascript with CakePHP?

PHP files can be used as external javascript files. Basically make a php file output valid javascript and use that php file as your javascript file: http://www.javascriptkit.com/javatutors/externalphp.shtml . Can this be done with cakephp since we don't specify php files in the browser but rather a directory based on controllers and their actions?

Upvotes: 0

Views: 1089

Answers (3)

minx
minx

Reputation: 33

Late answer, but anyway, this is how I did it.
When linking to external javascript file, don't forget to set inline to false like the one shown below:

$this->Html->script('scriptname', array('inline' => false));

Upvotes: 1

mdarwi
mdarwi

Reputation: 933

When you link a javascript file with

$this->Html->script('scriptname');

all that happens is that a tag is created in the HTML

<script type="text/javascript" src="path/to/webroot/js/scriptname.js"></script>

So, you can link whatever you'd like.

Upvotes: 0

Jan Hančič
Jan Hančič

Reputation: 53931

Sure, as long as you output valid JS, id does not matter what the URL looks like and what is behind that URL.

Upvotes: 0

Related Questions