-
Notifications
You must be signed in to change notification settings - Fork 0
Installation and Usage
-
You have downloaded and installed the lasted release of CakePHP 2.
-
You have downloaded the lastest release of ExtJS 4
Note that while this project is under MIT license, ExtJS is only available in a different license model. See http://www.sencha.com/products/extjs/license/
-
Download the Bancha source and place it into the plugins folder of the existing CakePHP installation. (You should then have a folder plugins/Bancha).
-
Configure your bootstrap (app/Config/bootstrap.php) by adding at the end
CakePlugin::load(’Bancha’); App::import(’Controller’, ’Bancha.Bancha’); App::import(’Behavior’,’Bancha.Bancha’);
-
Configure routes (app/Config/routes.php) by adding at the end
Router::parseExtensions('js'); Router::connect('/Bancha.js?models=*', array('controller' => 'Bancha', 'action' => 'index'));
-
Copy the Bancha API _plugins/Bancha/app/webroot/bancha.php into app/webroot/
-
Copy the Bancha JS plugins/Bancha/Lib/vendors/js/Bancha.js into app/webroot/js/
-
Place ext-all.js and ext-all-dev.js into app/webroot/js/ and the ExtJS ressources folder into app/webroot/css/
-
To use Bancha on a site include the files Bancha.js and js/Bancha.js in the layout. For production usage you may wanna add a parameter to already load all metadata on startup: js/Bancha.js?models=[all] or js/Bancha.js?models=[Article,User]
Done.
To expose the crud functions of an model to ExtJS follow these steps:
-
Add
$actas = array(”Bancha”);
to the models you want to expose -
Make sure that the primarys field of the model is called id (cake default)
-
Augment the controller to always have a return statement in the function. Return value of TRUE/FALSE indicated if the operation was successfull, or return a standard cake data array. For full list see Supported Controller-Method Results
You can find the two preferred ways to extend the standard scaffolded controller [here](https://github.com/Bancha/Bancha/wiki/Controller-Augmentation-Alternative-1) and [here](https://github.com/Bancha/Bancha/wiki/Controller-Augmentation-Alternative-2) Note: Currently Bancha can not handle Controller::setFlash() and Controller::redirect()
Side note: Bancha augments the models a bit, validations and save operations are only are executed on defined fields, validation will not fail if a field is missing - this is because ExtJS only send the changed fields in an edit request. If you don't like this set the BanchaBehavior setup config to array('useOnlyDefinedFields'=>false). Keep in mind to then use $model->saveFields($data,$options) instead of $model->save().
That's it, now you can write normal ExtJS code using Bancha.onModelReady(modelName,fn) and Bancha.getModel(modelName) or you take a look at our powerfull scaffolding classes which are using all the served meta data from cake to have create e.g. grids liks this: Ext.create("Ext.grid.Panel",{scaffold:'User'});