0

I have a file called script.php, this is some php and some javascript mixed together. The mime type of this file is forced to javascript, so this is a normal javascript file, but extension php.

I'm tryng to insert this inside my layout throuh script function. If write:

echo $this->Html->script('rsravenna/script.php'); 

cakephp will try to insert script.php.js, how can avoid the append of .js?

2 Answers 2

1

The appending of .js is hardcoded in the HtmlHelper->script() function. Is there anything in your app, that keeps you from just including your script manually?

<script type="text/javascript" src="myscript.php"></script>

Otherwise you could extend the HtmlHelper to pass the variable ext as part of the options array to HtmlHelper->assetUrl.

You could also do it the other way around, tell your server to parse .js-files in a specific folder as php to preserve the extension. If you're using apache, put this in your .htaccess:

AddType application/x-httpd-php .js

Now you should be able to rename your myscript.php to myscript.js and still get it parsed. This would enable you to use the standard script()-function.

Sign up to request clarification or add additional context in comments.

Comments

0

It's really not clear to me what you're trying to do. script is an HTML Helper used to include javascript not PHP.

You can do something like:

echo $this->Html->url('/rsravenna/script.php', true);

or

echo $this->Html->url(array(
    "controller" => "foo",
    "action" => "bar",
    "ext" => "php"
));

Why are you forcing the MIME type to .js ?

1 Comment

I assumed what he's trying to accomplish is dynamically generating Javascript with PHP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.