componentName.xml (Backend)
This file is the one that installs the component.
Basic structure of the file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
admin. componentName.php (Backend):
It is the first file to be executed when loading the component in the backend, and is responsible for controlling what action is going to be performed, according to act and task parameters.
The act parameter identifies which backend’s menu item was selected.
The task parameter tells us which action is going to be executed, such as save, delete, etc.
For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | getPath( 'admin_html' ) ); require_once( $mainframe->getPath( 'class' ) ); //Performs the includes of the needed files. $id = mosGetParam( $_REQUEST, 'cid', array(0) ); //Capture the variable passed by REQUEST. switch($act) { default switch($task) { default: list($option); break; case "save": save($option); break; } break; } break; //Function that lists the records from a table in the database. function list($option) { global $database, $mainframe; $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', 10 ); //Get the variable limit that is used for paging $limitstart = $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 ); //Get the variable limitstart that specifies from which record to begin displaying. $query = "SELECT COUNT(id) FROM #__example"; $database->setQuery($query); $total = $database->loadResult(); //Executes the query and returns the result in a variable, this function is used when the consult returns a single result. require_once("includes/pageNavigation.php"); //Includes the file cointaning the class for the paging. $pageNav = new mosPageNav( $total, $limitstart, $limit ); //Instantiate the page class. $query = "SELECT * FROM #__example"; $query .= " LIMIT ".$limitstart.", ".$limit; $database->setQuery($query); $rows = $database->loadObjectList(); //Executes the query returning the result into an objects array. HTML_Example::list($option, $rows, $pageNav); //Call the method that will generate the HTML from the list, and it gets as parameters the option the actual component will have, the array with the records, and the object with the paging. } //Function that saves a record in the database. function save($option) { global $database; $row = new presentacionTable($database); //Instance the class that to be created in the file componentName.class.php $row->bind($_POST)); //If the form's input names match with the names in the database table's fields, this method takes care to relate each form field with its respective column in the table. $row->date = date("Y-m-d H:i"); // Seats a particular field. $row -> store(); // Saves the values in the database. mosRedirect("index2.php?option=".$option, "Example saved!"); // The page is redirected to a specific address, the second parameter is the message to display. } ?> |
This file implements 2 actions: list and save.
The first lines includes the needed files, then receive the variables that come in for REQUEST. Next, we determine which action to execute according to the value of the act and task variables.
Then, we implement each of the necessary functions to perform the required tasks.
admin. componentName.html.php (Backend):
This file defines the class that will contain the different methods responsible for generating the HTML.
The basic structure of the file is:
1 2 3 4 5 6 7 |
toolbar. componentName.php (Backend):
This file controls which menu to display according to the received act and task parameters. The basic structure of the file is:
1 2 3 4 5 6 7 8 9 10 11 12 13 | getPath( 'toolbar_html' ) ); // Performs an include of the file named toolbar.componentName.html.php which has the HTML for the menu to display. switch ( $task ) { default: menuExample::DEFAULT_MENU(); // Load the default menu from the class menuExample. break; } ?> |
toolbar. componentName.html.php (Backend):
This file generates the menu to display. The basic structure of the file is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
componentName.class.php (opcional):
This file is used to create a class that will make it easier for us to save, edit and delete a record from the table using the methods inherited from the class mosDBTable.
In the example provided in the file admin.componentName.php we have used a class of this king, more specifically when using the methods bind(), store().
This class also allows us to load a record simply by using the load() method, which receives as parameters the record id.
Basic structure of the file:
1 2 3 4 5 6 7 8 9 10 11 12 13 | mosDBTable('#__tableName', 'id', $db); //This method receives 3 parameters: table name, field with the primary key, database connector. } } ?> |
componentName.php and componentName.html.php (Frontend):
These 2 files are used to perform actions in the frontend component. The file componentName.php has the same structure as the admin.componentName.php file. The file componentName.html.php has the same structure as the file named admin.componentName.html.php