# LeftAndMain ## Introduction LeftAndMain is the base class of all the admin area controllers. ## Best Practices ### Refreshing Please use LeftAndMain::ForceReload to reload the whole form-area after an Ajax-Request. If you just need to refresh parts of the form, please use javascript-replacement in the response of the original Ajax-Request. Consider using `[api:Form]` for compiling Ajax-Responses and automatic detection of Ajax/Non-Ajax-Calls. ### Custom Access Checking You can customize access control in `[api:LeftAndMain]`. :::php // mysite/_config.php LeftAndMain::add_extension('MyLeftAndMain'); // MyLeftAndMain.php class MyLeftAndMain extends Extension { function augumentInit() { // add custom requirements etc. } function alternateAccessCheck() { // custom permission checks, e.g. to check for an SSL-connection, or an LDAP-group-membership } } ## Subclassing There are a few steps in creating a subclass of LeftAndMain. ### MyAdmin.php The PHP file defining your new subclass is the first step in the process. This provides a good starting point: :::php class MyAdmin extends LeftAndMain { static $url_segment = 'myadmin'; static $url_rule = '$Action/$ID'; static $menu_title = 'My Admin'; static $menu_priority = 60; /** * Initialisation method called before accessing any functionality that BulkLoaderAdmin has to offer */ public function init() { Requirements::javascript('cms/javascript/MyAdmin.js'); parent::init(); } /** * Form that will be shown when we open one of the items */ public function getEditForm($id = null) { return new Form($this, "EditForm", new FieldSet( new ReadonlyField('id #',$id) ), new FieldSet( new FormAction('go') ) ); } } ### Templates Next, create templates, (classname)_left.ss and (classname)_right.ss. Again, here are a couple of starting points: * On the left, we're using the tree as a way of providing navigation. The left and side could be replaced with anything but LeftAndMain has built-in support for trees. * On the right, we have the skeleton that the form will be loaded into. MyAdmin_left.ss :::ss