Yii Framework Forum: CSS and JS autoloading - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CSS and JS autoloading as a controller property

#1 User is offline   saegeek 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 245
  • Joined: 09-December 09
  • Location:Montpellier - France

Posted 07 May 2012 - 10:48 AM

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()->...
And [for] their saying, "Indeed, we have killed the Messiah, Jesus, the son of Mary, the messenger of God ." And they did not kill him, nor did they crucify him; but [another] was made to resemble him to them. And indeed, those who differ over it are in doubt about it. They have no knowledge of it except the following of assumption. And they did not kill him, for certain.Rather, God raised him to Himself.
0

#2 User is offline   twisted1919 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 644
  • Joined: 23-October 10
  • Location:Romania

Posted 07 May 2012 - 07:26 PM

 public $cssFiles = array('*'//from where will you load this ???, '/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);');

0

#3 User is offline   saegeek 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 245
  • Joined: 09-December 09
  • Location:Montpellier - France

Posted 08 May 2012 - 03:25 AM

View Posttwisted1919, on 07 May 2012 - 07:26 PM, said:

 public $cssFiles = array('*'//from where will you load this ???, '/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/

And [for] their saying, "Indeed, we have killed the Messiah, Jesus, the son of Mary, the messenger of God ." And they did not kill him, nor did they crucify him; but [another] was made to resemble him to them. And indeed, those who differ over it are in doubt about it. They have no knowledge of it except the following of assumption. And they did not kill him, for certain.Rather, God raised him to Himself.
0

#4 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,778
  • Joined: 17-January 09
  • Location:Russia

Posted 08 May 2012 - 03:32 AM

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.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#5 User is offline   twisted1919 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 644
  • Joined: 23-October 10
  • Location:Romania

Posted 08 May 2012 - 06:36 AM

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.
2

#6 User is offline   saegeek 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 245
  • Joined: 09-December 09
  • Location:Montpellier - France

Posted 08 May 2012 - 10:58 AM

View Posttwisted1919, on 08 May 2012 - 06:36 AM, said:

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



Why not ? :lol:
And [for] their saying, "Indeed, we have killed the Messiah, Jesus, the son of Mary, the messenger of God ." And they did not kill him, nor did they crucify him; but [another] was made to resemble him to them. And indeed, those who differ over it are in doubt about it. They have no knowledge of it except the following of assumption. And they did not kill him, for certain.Rather, God raised him to Himself.
0

#7 User is offline   twisted1919 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 644
  • Joined: 23-October 10
  • Location:Romania

Posted 08 May 2012 - 03:07 PM

I made your day, didn't i ?:D
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users