The BasicBackend task for Joomla components creates a basic MVC for the administrator from a create table statement in a MySQL file. In the following example, we use a slight (but important) modification of customers table from the classicmodels database, which can be found here. The code we present below is implemented in the Classic models component, whose extension XML file is found in "TemplateManifests\classicautos.xml".
First we add the following task after the Main task in the extension XML file.
<task name="BasicBackend"> <parameters> <table>customers</table> <nameObject>customer</nameObject> <nameObjectList>customers</nameObjectList> <canEdit>true</canEdit> <canCreate>true</canCreate> <menu> <menu>true</menu> </menu> </parameters> </task>
Note that table, nameObject, and nameObjectList parameters are required parameters for the task to run correctly.
Now we tell the program where the "customers" table could be found. We do this by creating a MySQL file, named "classicautos_database.sql" located in the "TemplateManifests" folder, with a create table statement for the "customers" table. In our example, the SQL file contains the folloing code.
DROP TABLE IF EXISTS `#__customers`; CREATE TABLE `#__customers` ( `id` int(11) NOT NULL AUTO_INCREMENT, `customerName` varchar(50) NOT NULL, `contactLastName` varchar(50) NOT NULL, `contactFirstName` varchar(50) NOT NULL, `phone` varchar(50) NOT NULL, `addressLine1` varchar(50) NOT NULL, `addressLine2` varchar(50) DEFAULT NULL, `city` varchar(50) NOT NULL, `state` varchar(50) DEFAULT NULL, `postalCode` varchar(15) DEFAULT NULL, `country` varchar(50) NOT NULL, `salesRepEmployeeNumber` int(11) DEFAULT NULL, `creditLimit` decimal(10,2) DEFAULT NULL, PRIMARY KEY (`id`), KEY `salesRepEmployeeNumber` (`salesRepEmployeeNumber`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
The primary key must be an integer, named "id", and set to AUTO_INCREMENT, as above, for the generated files to work correctly. See Component MySQL File for additional details on the currently supported MySQL syntax. Note that the above code will be used by the Joomla Installer to create the "customers" table when the Classic models component is first installed.
After saving the contents of the above file in the "TemplateManifests" folder, the following line is then added to the parameters section of the "TemplateManifests\classicautos.xml" file, so that the program can find it.
The attribute relUri="true" tells the program that the MySQL file is in the same folder as the extension XML file.
In conclusion, when the extension file is run, it will create MVC files in the administrator part of the site, allowing the user to view, edit, and create entries in the "customers" table. The "customers" table will also be created using the above MySQL code when the Classic models component is first installed. Additional customization of the fields extracted from the "customers" table can be made when the extension file is run.