If you haven't already lets simply start this file of with:
class HelloWorldLeftAndMain extends LeftAndMain {
}
The first thing you should do, is define the $url_segment
that will be used to access the interface, and the title ($menu_title
) that will appear in the side navigation menu of the administration panel:
private static $url_segment = 'helloworld';
private static $menu_title = 'Hello World';
The following configuration variable(s) are optional and not used in this guide:
private static $menu_icon = 'helloworld/path/to/my/icon.png';
private static $url_rule = '/$Action/$ID/$OtherID';
LeftAndMain
allows you to override the init
method in it's parent, we can use this to require specific files for our interface. Undoubtedly you should always need to require a CSS stylesheet that will style the elements for your user interface.
As a tip, it's recommended to never rely on the CSS classes provided by the CMS as these are subject to change without notice and will subsequently destroy the Look & Feel of your UI (for example, 3.*
to 4.*
has seen a complete makeover of the interface therefore any CSS classes you relied on in 3.*
need to be restyled for conversion to 4.*
)
So lets add our helloworld/css/styles.css
file:
public function init() {
parent::init();
Requirements::css('helloworld/css/styles.css');
//Requirements::javascript('helloworld/javascript/script.min.js');
}
We don't need any Javascript functionality for this example but in the above I have included how one would achieve adding Javascript a file using the Requirements class.
After which you can adopt what you have been used to when dealing Page_Controller
such as $allowed_actions
etc with one notable difference, however
You CANNOT override
index()
.
Instead index()
is assumed as HelloWorldLeftAndMain_Content.ss
and from there, it's required to deal with the indexes display via template functions (see example below)
class HelloWorldLeftAndMain extends LeftAndMain {
private static $url_segment = 'helloworld';
private static $menu_title = 'Hello World';
private static $allowed_actions = array(
'some_action'
);
public function init() {
parent::init();
Requirements::css('helloworld/css/styles.css');
//Requirements::javascript('helloworld/javascript/script.min.js');
}
public function Hello($who=null) {
if (!$who) {
$who = 'World';
}
return "Hello " . htmlentities($who);
}
}