how to correctly fill "packages" properties ?

Hi,

I want to use my own JS library in one of my own widgets.

I want to add this js file to packages like this





			$cs->packages[] = array(

				'my_name' => array(

					'basePath' => '',

					'baseUrl' => '',

					'js' => '',

					'depends' => '',

				)

			)






But i’m not sure what i should write in all these “fields” ?

I want to make and keep this widget with all resources (css and js) in one place, for easy to move (from one to another project)

Questions:

  1. where in file structure i should keep CSS and JS files related with current widget ? (The widget kept under component folder)

  2. What should I use as a basePath, baseUrl ?

  3. How can I make it dependable from jQuery framework ?

  4. Can I use this package, after successful definition above, as




$cs->registerPackage('my_name');



?

  1. How can join all JS from all other my widgets into one JS, minify and compress it ??

Thanks.

Your project folder is public accept the protected folder where basically all your logic and views reside. Either you can keep it in the same place as your widget views like widget.[css|js] but then you have to publish these files with yii’s assetmanager, this is what the ‘assets’ folder (in your public, top level directory) is for. If you find this too complicated you could make a directory css/ and js/ in your top level directory (where the entry script index.php resides).

From CClientScript.php:


	    public $scriptMap=array();

058	    /**

059	     * @var array list of custom script packages (name=>package spec).

060	     * This property keeps a list of named script packages, each of which can contain

061	     * a set of CSS and/or JavaScript script files, and their dependent package names.

062	     * By calling {@link registerPackage}, one can register a whole package of client

063	     * scripts together with their dependent packages and render them in the HTML output.

064	     *

065	     * The array structure is as follows:

066	     * <pre>

067	     * array(

068	     *   'package-name'=>array(

069	     *     'basePath'=>'alias of the directory containing the script files',

070	     *     'baseUrl'=>'base URL for the script files',

071	     *     'js'=>array(list of js files relative to basePath/baseUrl),

072	     *     'css'=>array(list of css files relative to basePath/baseUrl),

073	     *     'depends'=>array(list of dependent packages),

074	     *   ),

075	     *   ......

076	     * )

077	     * </pre>

078	     *

079	     * The JS and CSS files listed are relative to 'basePath'.

080	     * For example, if 'basePath' is 'application.assets', a script named 'comments.js'

081	     * will refer to the file 'protected/assets/comments.js'.

082	     *

083	     * When a script is being rendered in HTML, it will be prefixed with 'baseUrl'.

084	     * For example, if 'baseUrl' is '/assets', the 'comments.js' script will be rendered

085	     * using URL '/assets/comments.js'.

086	     *

087	     * If 'baseUrl' does not start with '/', the relative URL of the application entry

088	     * script will be inserted at the beginning. For example, if 'baseUrl' is 'assets'

089	     * and the current application runs with the URL 'http://localhost/demo/index.php',

090	     * then the 'comments.js' script will be rendered using URL '/demo/assets/comments.js'.

091	     *

092	     * If 'baseUrl' is not set, the script will be published by {@link CAssetManager}

093	     * and the corresponding published URL will be used.

094	     *

095	     * When calling {@link registerPackage} to register a script package,

096	     * this property will be checked first followed by {@link corePackages}.

097	     * If a package is found, it will be registered for rendering later on.

098	     *

099	     * @since 1.1.7

100	     */

see ‘depends’ in 1.

If that’s what the wonderful yii framework docs tell you then you better believe it (or file a bug).

By writing some code? Getting all scripts via clientscript and then using your favorite minifying algorithm. Maybe if you’re lucky Yii already has some of this functionality (don’t think so)

Thank you very much for rewriting here manual, it’s a big help.

All what i was need is LIVE example, that’s it.

Btw, I already solved it. And without couple debugging and reading source code it could’t be done :)




			$cs->packages['any_unique_name'] = array(

				'basePath' => 'application.components.views.my_widget_class_name',

				// 'baseUrl' => '',

				'js' => array('any_js_file_name.js'),

				'depends' => array('jquery'),

			);

			

			$cs->registerPackage('any_unique_name');



all widget related resources should be placed (in this case) here

/protected/components/views/my_widget_class_name

In this case everything will be used via AssetManager.

hi x00xer could you create a tutorial on yii wiki for this or outline step by step here in forum how yuo did this