create file inside Css

hello all,

I want to create a css file into the folder css code.

I tried this:


 $my_file = Yii::app()->baseUrl . '/css/test.css';

       //   $my_file = Yii::app()->basePath . '/css/test.css'; it works

        $handle = fopen($my_file, 'w') or die('Cannot open file:  '.$my_file); //implicitly creates file

        

but I get this error


fopen (/ ... / ... / css / test.css): failed to open stream: No such file or directory



but if I create with BasePath, when I’m going to include it finds the file

You’re trying to open an url for writing, which won’t work.

It works with basepath as that’s the actual location of the file on disk.

thanks for answer

i try this


$my_file = Yii::app()->basePath . '/css/test.css';

and load my Css in my page with this code:


        Yii::app()->clientScript->registerCssFile(Yii::app()->basePath . '/css/test.css');



but i have file Not Found

You don’t need to specify basepath when registering.

If the css folder is at the root you only need,


Yii::app()->clientScript->registerCssFile('/css/test.css');

oh my mistake, thanks a lot