Skip to content
This repository has been archived by the owner on Oct 10, 2019. It is now read-only.

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
neilime committed Oct 10, 2013
1 parent 0887ec7 commit c265de0
Showing 1 changed file with 37 additions and 37 deletions.
74 changes: 37 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ The default configuration is setup to run with "Application ZF2 Skeleton"

### 2. Assets

You can define assets for modules / controllers / action
You can define assets for modules / controllers / action

Exemple :
Exemple :

```php
```php
<?php
return array(
//...
Expand Down Expand Up @@ -196,7 +196,7 @@ The default configuration is setup to run with "Application ZF2 Skeleton"
),
//...
);
```
```

- For each asset, you can specify files or directories. All these elements are related to the asset path by default,
but you can specify an absolute path or use the constants "@zfAssetsPath" and "@zfRootPath".
Expand Down Expand Up @@ -245,45 +245,45 @@ If you specify a directory, all files matching the asset type (css, less, js, me

### 3. Custom Js

This function allows you to dynamically include javascript files. For exemple, files specific to user settings.
In this case, your controller that need these file have to extend `AssetsBundle\Mvc\Controller\AbstractActionController`.
This function allows you to dynamically include javascript files. For exemple, files specific to user settings.
In this case, your controller that need these file have to extend `AssetsBundle\Mvc\Controller\AbstractActionController`.

__Attention !__ Jscustom process does not cache javascript, due to performance reasons
__Attention !__ Jscustom process does not cache javascript, due to performance reasons

Then create a jscustomAction function into your controller :
Then create a jscustomAction function into your controller :

```php
public function jscustomAction($sAction = null){
//Check params, it's not mandatory
if(empty($sAction)){
$sAction = $this->params('js_action');
if(empty($sAction))throw new \InvalidArgumentException('Action param is empty');
}

$aJsFiles = array();
switch(strtolower($sAction)){
case 'myActionName':
//Put here all js files needed for "myActionName" action
$aJsFiles[] = 'js/test.js';
$aJsFiles[] = 'js/test.php';
break;
}
return $aJsFiles;
```php
public function jscustomAction($sAction = null){
//Check params, it's not mandatory
if(empty($sAction)){
$sAction = $this->params('js_action');
if(empty($sAction))throw new \InvalidArgumentException('Action param is empty');
}
```

Edit layout file:

```php
//Into head

//Production case
if(!empty($this->jsCustomUrl))$this->plugin('InlineScript')->appendFile($this->jsCustomUrl.'?'.time()); //Set time() force browser not to cache file, it's not mandatory
//Development case
elseif(is_array($this->jsCustomFiles))foreach($this->jsCustomFiles as $sJsCustomFile){
$this->plugin('InlineScript')->appendFile($sJsCustomFile);
$aJsFiles = array();
switch(strtolower($sAction)){
case 'myActionName':
//Put here all js files needed for "myActionName" action
$aJsFiles[] = 'js/test.js';
$aJsFiles[] = 'js/test.php';
break;
}
```
return $aJsFiles;
}
```

Edit layout file:

```php
//Into head

//Production case
if(!empty($this->jsCustomUrl))$this->plugin('InlineScript')->appendFile($this->jsCustomUrl.'?'.time()); //Set time() force browser not to cache file, it's not mandatory
//Development case
elseif(is_array($this->jsCustomFiles))foreach($this->jsCustomFiles as $sJsCustomFile){
$this->plugin('InlineScript')->appendFile($sJsCustomFile);
}
```

# Tools

Expand Down

0 comments on commit c265de0

Please sign in to comment.