CSS and JS autoloading

It would be nice to allow to enable autoloading of CSS and JS files from the controller.

example:




Class myController extends Controller {

    public $cssFiles = array('*','/css/');

    public $jsFiles = array('*','/js/');


    public function actionIndex() {

    // And of course, to override we will use :

    $this->cssFiles = array('style.css,main.css','/css/'));

    $this->jsFiles = array('jquery.js','/js/'));

    ...

}



Also "ClientScript::" syntax should be enabled instead of Yii::app()->getClientScript()->…




 public $cssFiles = array('*'//from where will you load this <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />, '/css/');

 public $jsFiles = array('*'//same ,'/js/');



The idea itself is bad, clientscript is good as it is right now, i don’t see why complicate things.

If you want, you can always create a helper around CClientScript for these kind of things




Also "ClientScript::" syntax should be enabled instead of Yii::app()->getClientScript()->... 



Why make the class methods static ?

Again, you can have your own ClientScript class helper with static methods if you’d like:




class ClientScript{

   [...]

   public static function registerScriptFile()

   {

      return call_user_func_array(Yii::app()->clientScript,__FUNCTION__,func_get_args());

   }


   public static function registerScript()

   {

      return call_user_func_array(Yii::app()->clientScript,__FUNCTION__,func_get_args());

   }

   [...]


}



And call




ClientScript::registerScriptFile('http://');

ClientScript::registerScript('my-script','alert(1);');



The goal of a framework is to minimalize as much as possible the develloper work so why CClientScript could not be static ?

And why JS and CSS could not be autoloaded ?

The syntax could be :




public $cssFiles = array('*','application.css'); // this means /protected/css/



saegeek

Making it static will kill an ability to extend it. If you want a shorthand, you can just add the following to your index.php:




/**

 * @return CClientScript

 */

function cs() {

  return Yii::app()->clientScript;

}



As for autoloading, see script packages feature that’s in 1.1 already.




public $cssFiles = array('*','application.css'); // this means /protected/css/



What if i use themes ? What if my assets are (as they should be) outside of the protected folder ?

You have CAssetManager::publish() to publish files just as you need, then use the generated url to reference the files. It’s too easy as it is right now.




The goal of a framework is to minimalize as much as possible the develloper work so why CClientScript could not be static ?



Let’s not fool our self here, i know that we’re lazy and probably we would want :




Yii::createWebApplication('Yii, make me a shop website, that rocks the world')->run();



But some not anybody have same needs, that’s why the framework needs to have a certain level of abstraction.

Why not ? :lol:

I made your day, didn’t i ?:D

10 years after, we have something like GitHub’s Copilot which may… may just be able to make this dream come true :relieved: