How many ways can you generate a CakePHP Admin interface? A summary of the available methods, as well as an intro to CakeAdmin, a class-based admin generation tool.
2. ~WHOAMI
• Jose Diaz-Gonzalez
• Resident IRC Troll (savant)
• Rants at http://josediazgonzalez.com
➘
• Harasses as @savant
me
• Codes as josegonzalez on github
• Works at @seatgeek
not me
➘
3. WHO IS THIS TALK FOR?
• Anyone building CMS’ for a living
• Those needing quick, extensible CRUD applications
• Anyone looking for a boring challenge
4. WHAT THE HELL IS THIS?
• var $scaffold = true;
• ../cake/console/cake bake
• cake bake skeletons
• admin generation
6. SCAFFOLDING
• Generic application auto-generation
• InCakePHP, introspects the Model::schema() and
relationships to pull in data
• Dumb, never recommended for production, not easy to
manipulate
12. GENERIC METHODS
• Create
index()/view()/add()/edit()/delete() methods in your
AppController
• Have callbacks to disable in specific Controllers
• Able to override in child Controllers
13. /**
* Handles index requests.
*
* @return void
* @access public
*/
public function index() {
// Only do this work if our concrete controller has not.
if (!isset($this‐>viewVars[Inflector::pluralize($this‐>modelClass)])) {
$this‐>set(array(
Inflector::pluralize($this‐>modelClass) => $this‐>paginate(
$this‐>modelClass,
/**
* Here we toss in any conditions that were found as named
* parameters and which match up to a column in the model
* schema.
*/
array_intersect_key(
$this‐>params['named'],
$this‐>{$this‐>modelClass}‐>schema()
)
)
));
}
}
From https://github.com/joebeeson/crumbs/blob/develop/app_controller.php
15. CAVEATS
• Has to be generic enough to use across controllers
• Only portable if built as a plugin library (ie. LazyModel)
• Must remember to build disabling code
17. CAKE BAKE
• You can now view the generated code and modify at will
• Have to re-bake constantly
• Everyone uses it; No one customizes it
• Same issues as Scaffold
• NOT === var $scaffold
18. BAD CAKE BAKE
• Lets use Model::scaffold = ‐1 please
• Generated view() can result in an empty page
• Generated delete() lets crawlers potentially auto-delete
site
• Model::read() usage is evil
• Asks too many questions; Can’t I just answer once and rebake?
19.
20. EXTENDING THIS?
• Templates: app/vendors/shells/templates
• Models are simple to access in templates
• Do you follow “conventions” or allow configuration?
• May need custom shell for extra configuration
22. CAKE SKELETONS
• Can’t use in existing applications
• Assume you’ll always follow the same conventions
• Hard to upgrade bootstrapped apps in automated fashion
• Good for “chop-shops” and freelancers on new apps
27. • Generators generate generators
• Scaffolding similar to bake
• Heavy community use
• http://railswizard.org/
^ Someone make this for CakePHP ^
ESSENTIALLY
CAKE BAKE+SKELETONS
29. • Port of MerbAdmin
• Ruby DSL Configuration
• Similar to var $scaffold
• Works with existing
applications
• Actively
Developed, https://github.com/sferik/rails_admin
Unofficial
37. WHY
• Need custom admin interface on top of phpmyadmin
• Can’t use Croogo/Infinitas/etc.
• Need to replicate similar admin interfaces across projects
• Let less technical developers create their own interfaces
40. PHP-BASED CONFIGURATION
class CategoryCakeAdmin extends CakeAdmin {
/**
* Where do I “scaffold” this?
*
* @var string
*/
public $plugin = 'dashboard';
}
47. CREATING NEW ACTIONS
• Needs an *ActionConfig class
• Templates for Controller/View - Model optional
• Similar to Cake Bake Templates
• Access to a model and the Admin class config
48. WHATS IN AN ACTION
<?php
class CakeAdminIndexConfig extends CakeAdminActionConfig {
// Guess
var $defaults = array( /* some options */);
// Should we enable this by default
var $enabled = true;
// Plugin where the templates for this action are located
var $plugin = 'cake_admin';
// Action type
var $type = 'index';
// How do we "link" to this method
var $linkable = 'List {{modelname}}';
// Custom model methods (find, related)
var $methods = array('find');
// How do we merge our defaults and configuration?
function mergeVars($admin, $configuration = array()) {
}
}