Client Script .. but php dependent!

Simple question: I have a javascript and some of the code is depended on model constants etc. so this is why I have php inside this code. I guess the code $cs->registerScriptFile(’/javascript/somefile.js’); is out of the question. Am I correct?

Currently I have renamed somefile.js to --> somefile.php and use the require(‘somefile.php’) to get the same result.

Is this the proper way to do it in Yii ?


Try using this instead from inside your view/layout/widget etc

Thank you very much for clarifying it. In case someone has the same problem, below is the solution. Ok I stuck in a moment how to get the contents of a php file after being processed in the server and the get_include_contents function was the solution :)

function get_include_contents($filename)


    if (is_file($filename))



        include $filename;

        $contents = ob_get_contents();


        return $contents;


    return false;



$somescript= get_include_contents($somefilepath); 


$cs->registerScript($somefilepath, $somescript);