How to use external PHP file in СakePHP 2?

Use php as external javascript file in CakePHP 2.0

  • I know that you can use a php file as an external javascript file like below: <script type="text/javascript" src="myscript.php"></script> But how would you do this in CakePHP 2.0? $this->Html->script('external_js', false); automatically adds the .js extension. This page explains what I want to do: http://nuts-and-bolts-of-cakephp.com/2009/04/03/blend-php-and-javascript-in-cakephp/ but it's out of date. This method doesn't work with CakePHP 1.3+. Any ideas?

  • Answer:

    You can get around the automatic addition of the .js extension by adding a question mark at the end of the filename. The Html->script function will add '.js' to any input that does not end in '.js' AND does not contain a '?'. $this->Html->script('external_js.php?');

Brian at Stack Overflow Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.