Replacer
Provides a simple graphical interface to replace strings in CakePHP's output using regular expressions., (*1)
Possible usages :
- Format text (ex : m2 => m², mysql => MySQL, cAkePHp => CakePHP...)
- Add code to every page (</body> => <script>analytics();</script></body>)
- Add a CDN to remote assets (src="js/script.js" => src="http://cdn.example.com/js/script.js")...
- ..., (*2)
Setup
1) Clone repository :, (*3)
$ cd /my/app/root && git clone git://github.com/asper/Replacer.git Plugin/Replacer
2) Load plugin in app/Config/bootstrap.php
:, (*4)
CakePlugin::load(array(
'Replacer' => array(
'routes' => true
)
));
3) Create schema :, (*5)
$ cd /my/app/root && cake schema create Replacer.replacer
4) Open app/webroot/index.php
and search for (l. 96 for CakePHP 2.1) :, (*6)
$Dispatcher->dispatch(new CakeRequest(), new CakeResponse(array('charset' => Configure::read('App.encoding'))));
5) Replace this line with :, (*7)
App::import('Lib', 'Replacer.ReplacerResponse');
$Dispatcher->dispatch(new CakeRequest(), new ReplacerResponse(array('charset' => Configure::read('App.encoding'))));
6) Enable admin
routing prefix by uncommenting Configure::write('Routing.prefixes', array('admin'));
in app/Config/core.php
, (*8)
7) Navigate to http://my-app/admin/replacer
and start configuring the plugin, (*9)
Usage
Replacer Plugin is composed of 2 main sections Replacements
and Scopes
, (*10)
Replacements
let you substitute strings in output using regular expressions, (*11)
Scopes
let you choose where these substitutions should occur, (*12)