With CakePHP-Plist it’s easy to generate Plists from your CakePHP app. It uses a view class, so you can use it by extension parsing, just like the built-in JSON support. Both plain and binary plists are supported.
- Add the plugin to your app.
- Import the plugin in your
bootstrap.php
by addingCakePlugin::load('Plist', array('bootstrap' => false, 'routes' => true));
. Make sure you enableroutes
or addRouter::parseExtensions('plist’);
to your own route file. - Replace the existing
$Dispatcher->dispatch()
call in yourwebroot/index.php
to the code below. This is necessary because CakePHP doesn’t know how to handleplist
files.
$Dispatcher->dispatch(
new CakeRequest(),
new CakeResponse(array(
'type' => array(
'plist' => 'application/xml',
'plist-binary' => 'application/x-plist',
)
))
);
- Load the
RequestHandler
in either theAppController
or any other controller you would like to use it in. You need to let theRequestHandler
know about the plugin:
public $components = array('RequestHandler' => array(
'viewClassMap' => array(
'plist' => 'Plist.Plist'
)
));
To generate plists from your app, you simple use CakePHP’s serialization method, as shown on this web page: http://book.cakephp.org/2.0/en/views/json-and-xml-views.html.
Simple example to test the installation:
class PlistTestController extends AppController {
public $uses = array();
public function test() {
$data = array(
'names' => array(1, 2, 3)
);
$_serialize = array_keys($data);
$this->set(compact('_serialize') + $data);
}
}
Open /plist_test/test.plist
to see if it works. If both JSON (or even XML) and Plist extension parsing is enabled, you can get either of them by changing the extension.
To get a binary plist, you can either set a _binaryPlist
view var to true
to get a single action rendered as a binary plist or set a binaryPlist
config value to true.
If you have a config value set, the view var will overrule it.