Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CakeAdmin, the Answer to DjangoAdmin, but for CakePHP
<?php
class PostCakeAdmin extends CakeAdmin {
/**
* Name of the model. Must be overridden in order to create a
* valid admin section, unless you want everything to reference
* a Cake Model
*
* @var string
*/
var $modelName = 'Post';
/**
* Name of the primaryKey of the model
*
* @var string
*/
var $primaryKey = 'id';
/**
* Name of the displayField of the model
*
* @var string
*/
var $displayField = 'required';
/**
* Instead of prefixes, we use plugins to set a valid prefix
* Pluginizing the app means we can isolate the "admin" portion
* From everything else. One can also App::import() the plugin
* Models/Views and import the admin goodness.
*
* Isolating the CakeAdmin'ed app from everything else is good
* for ease of updating code without have to worry about a
* re-admin deleting customizations
*
* @var string
*/
var $plugin = 'admin';
/**
* Apply all these Behaviors to the Model
*
* @var array
*/
var $actsAs = array('Logable.Logable', 'Upload.Upload', 'Ratings.Ratings', 'Tags.Tags', 'Comments.Comments', 'Categories.Categories');
/**
* Apply all these Components to the Controller
*
* @var string
**/
var $components = array();
/**
* Apply all these Helpers to the Controller
*
* @var string
**/
var $helpers = array();
/**
* Model validation rules
*
* alias => rule, where rule can be an array. If the rule is a string or the
* message is missing, the message is set to some default.
*
* Validation rules are wrapped in __() calls, meaning your admin section
* can be localized at a later date and time.
*
* @var array
*/
var $validate = array(
'content' => array( // field names point to an array of rules
'required' => 'notempty', // where the key is the name of the rule
'maxLength' => array('maxLength', 255), // and the value is the rule itself
'inList' => array(
'rule' => array('inList', array(true, 'b', null)),
'allowEmpty' => true,
'on' => 'create',
'message' => 'ham fucking sammich bitches'
)
)
);
/**
* Relations to use on this model. Defaults to belongsTo.
* Assumes conventions, but you can configure if necessary
*
* @var string
*/
var $relations = array(
'belongsTo' => array('User')
);
/**
* Customize the views further from the base
*
* @var array
*/
var $actions = array(
'index' => array(
'type' => 'index',
'enabled' => true,
'config' => array(
'fields' => array('id', 'required', 'type_id'),
'list_filter' => array('type_id' => array('1' => 'Links', '2' => 'Text', '3' => 'Youtube')),
'link' => array('id', 'required'),
'search' => array('id', 'required' => 'title'),
'sort' => array('id', 'required', 'approved'),
)
),
'add' => array(
'type' => 'add',
'enabled' => true,
'config' => array(
array('fields' => array(
'required' => array('label' => 'Title', 'type' => 'text'),
'description' => 'Content'
)),
array(
'title' => 'Advanced Options',
'classes' => 'collapsed',
'fields' => array('approved', 'tags'),
)
)
),
'edit' => array(
'type' => 'edit',
'enabled' => true,
'config' => array(
array('fields' => array(
'required' => array('label' => 'Title', 'type' => 'text'),
'description' => 'Content'
)),
array(
'title' => 'Advanced Options',
'classes' => 'collapsed',
'description' => 'advanced options for a post',
'fields' => array('approved', 'tags'),
'readonly' => array('created', 'modified'),
)
)
),
);
/**
* Auth Configuration
* We can decide which actions we want to require auth for
* Authentication can be implemented by some plugin adapter, app-wide
*
* @var string
*/
var $auth = array(
array(
'actions' => array('add', 'edit', 'delete'),
'auth' => array('group' => 'admin')
),
array(
'actions' => array('history', 'changelog'),
'auth' => true // As well as how to auth that user
)
);
/**
* AuthImplementation
*
* Either Acl, Auth, Authsome.Authsome, or Sanction.Permit
*
* Acl requires Auth, Sanction.Permit requires Authsome
*
* @var array
*/
var $authImplementation = 'Sanction';
/**
* Use sessions?
*
* @var boolean
* @default true
*/
var $sessions = true;
/**
* Automagic Webservice?
*
* @var boolean
* @default false
**/
var $webservice = false;
/**
* Action to redirect to on errors
*
* @var string
* @default index
*/
var $redirectTo = 'index';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment