Reputation: 181
I have an app in Yii and i want to ajax form submition without inline script unlike this link said, because inline script is bad for SEO.
So i create php file and put my js+php code in it with header
Header("content-type: application/javascript");
And include it as Javascript file. But java script return this error :
Fatal error: Class 'Yii' not found in /var/www/mydomain/js/sendmessage.php on line 16
Which line 16 contains:
var sendurl = request->getUrl() ?>+"/handler";
What should i do to make it work ?
Upvotes: 0
Views: 121
Reputation: 1120
Your problem is that Yii is not yet initiated in your file.
You should probably make a JsController
or something like that, and let it serve the js content for you instead of just making one external file like that. That will ensure that you have all the classes loaded that you want.
I mean, you wouldn't create a PHP file like that for anything else on your website right? So why do quickfixes just because it's js.
Upvotes: 0