Using php as external javascript with CakePHP?
PHP files can b开发者_开发百科e 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?
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));
Sure, as long as you output valid JS, id does not matter what the URL looks like and what is behind that URL.
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.
精彩评论