Releases for sf 1.1
| Version |
License |
API |
Released |
|
0.2.0beta
|
MIT license |
0.2.0beta
|
24/04/2007 |
Releases for sf 1.0
| Version |
License |
API |
Released |
|
0.2.0beta
|
MIT license |
0.2.0beta
|
24/04/2007 |
Copyright (c) 2004-2007 Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Changelog for release 0.2.0 - 24/04/2007
Not available
Other releases
Release 0.2.0 - 24/04/2007
Not available
Installation for sf 1.1
php symfony plugin:install sfPJSPlugin --release=0.2.0
Installation for sf 1.0
php symfony plugin-install http://plugins.symfony-project.org/sfPJSPlugin
PEAR
Download the PEAR package
Repository
Go to the repository: http://svn.symfony-project.com/plugins/sfPJSPlugin
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: [sfPJS](default,)
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:
<?php use_helper('PJS') ?>
<?php use_pjs('targetModule/targetAction?name=fabien') ?>
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 <?php echo $name ?>, it is already <?php echo date('d/m/Y', $time) ?>');
Alternative syntaxes
You can also include the dynamic JavaScript in one of the following ways:
<?php sfPJSHelper::use_pjs('targetModule/targetAction?foo=bar') ?>
<script src="<?php echo pjs_path('targetModule/targetAction?foo=bar') ?>" />
<script src="<?php echo sfPJSHelper::pjs_path('targetModule/targetAction?foo=bar') ?>" />
Known limitations
Internet Explorer is known to cache JavaScript files regardless of HTTP headers. This is means that your template changes, the client will never see it.
To bypass this limitation, you should add a version parameter to each call to the PJS helpers.
<?php use_pjs('targetModule/targetAction?name=fabien&version=1') ?>
Change the version each time you change the template.
If your template relies on session parameters, you must use a random / incremental version to forbid client side caching completely.
<?php use_pjs('targetModule/targetAction?name=fabien&version='.time()) ?>
<?php use_pjs('targetModule/targetAction?name=fabien&version='.uniqid()) ?>
<?php use_pjs('targetModule/targetAction?name=fabien&version='.rand(1000, 9999)) ?>
This is an experimental plugin and as such, the API can change.
Changelog
2007-04-24 | 0.2.0 beta