= sfPJS plugin = The `sfPJSPlugin` provides a MVC way to include JavaScript generated by PHP code. It also provides a new JavaScript view class and relies on .pjs templates. == Installation == * Install the plugin {{{ symfony plugin-install http://plugins.symfony-project.com/sfPJSPlugin }}} * Enable the `sfPJS` module in your application `settings.yml` {{{ all: .settings: enabled_modules: [default, sfPJS] }}} * Replace the following lines in `web/.htaccess` {{{ # we skip all files with .something RewriteCond %{REQUEST_URI} \..+$ RewriteCond %{REQUEST_URI} !\.html$ RewriteRule .* - [L] }}} by {{{ # we skip all files with .something RewriteCond %{REQUEST_URI} \..+$ RewriteCond %{REQUEST_URI} !\.html$ RewriteCond %{REQUEST_URI} !\.pjs$ RewriteRule .* - [L] }}} * Clear you cache {{{ symfony cc }}} * You're done. == Usage == To link to a dynamic JavaScript file generated by a symfony action, use the following syntax: {{{ }}} The `targetModule/targetAction` will be executed by symfony, so it can contain any usual action code: {{{ class targetModuleActions extends sfActions { ... public function executeTargetAction() { // Business logic here, as usual $this->name = $this->getRequestParameter('name'); // Let's store the time $this->time = time(); } } }}} The `targetAction` view has the layout disabled by default and the response content type is automatically changed to `application/x-javascript`. Unlike normal actions, PJS actions look for a template ending with `.pjs` instead of `.php`. For this example, the default rendered template is `targetActionSuccess.pjs`: {{{ alert('Hello , it is already '); }}} == Alternative syntaxes == You can also include the dynamic JavaScript in one of the following ways: {{{