defined('_JEXEC') or die;
class BreedControllerBreeds extends JControllerAdmin
public function getModel($name = 'breed', $prefix = 'BreedModel', $config = array())
$model = parent::getModel($name, $prefix, array('ignore_request' => true));
We have gone through the main controller before. We can declare any task in that controller but it is better to separate the tasks, connected to respective views into their corresponding sub controllers, also known as application controllers. It is already programmed in Joomla JController class, how to access a sub controller from the task request variable, using the dot notation. The main function of sub controller is same as main controller, just it is used to easily organize the code.
All sub controllers are grouped in a “controllers” folder, which is placed in the component root directory. We have created a controller in the respective directory, called breeds.php, as listed above. It will be used to process all taks, originating from breeds view. We have to also put an index.html file in this folder.
As you can see in the code, we have used jimport to import controller library. After that we are extending our sub controller class from the JControllerAdmin class. Controller name has a special format, like, the name of component, “Breed”, the word “Controller” and then the name of sub controller, “Breeds”. What we are doing in this class is, we are overriding getModel method in the JControllerAdmin class. To this method, we are passing the model name “breed” in the argument list and then the class prefix and after that there is a configuration array. Then we are calling the parent getModel() function through the “model” property and pass a specific configuration option called “ignore_request”. It is always a good practice, when the sub controller is in use, model should not be make to look at the request so that controller should have complete control over model state and to do that, we have passed the configuration option “ignore_request”, a value of true.
defined('_JEXEC') or die;
class BreedTablebreed extends JTable
public function __construct(&$db)
parent::__construct('#__breed_breed', 'id', $db);
In this step, we are creating new folder called “tables” under the component folder, to contain any table files that the component will use. Then we are creating a file in the tables folder, to connect with our breeds table, called “breed.php”. The constructor in the table class calls the parent class constructor and provides name of the database table and the primary key as arguments. We call the table name with its name, prefix with “#__” string. Joomla replaces this string with the database prefix which it picks from configuration file.
Now, in the change order action, there would be an update to database table, for the order of a specific record. To accomplish this, there must be a form holding the id value of that record and update its order status on the basis of that id. So, in this step, we are going to create a small form here to hold our id field.
In joomla, forms are created in an xml form, which are then pickedup and interpreted by model and then passed to the view for display. The xml based fors are stored in the forms folder, in the models directory.
In the above mentioned code, we have started an xml file, with an xml prolog and from the next line, we are starting the form and then a fieldset, which will be wrapping aour all fields related code. But currently we want only the id field, with the value of the mapping table id field. Its value will be updated when we will perform a change order operation and will be updated in the table as well. The concept of mapping the field names with that of the table columns is called Object relational mapping (ORM) and is the base of joomla CRUD based operations.
defined('_JEXEC') or die;
class BreedModelBreed extends JModelAdmin
protected $text_prefix = 'COM_BREED';
protected $item = null;
public function getTable($type = 'Breed', $prefix = 'BreedTable', $config = array())
return JTable::getInstance($type, $prefix, $config);
public function getForm($data = array(), $loadData = true)
// Initialise variables.
$app = JFactory::getApplication();
// Get the form.
$form = $this->loadForm(
array('control' => 'jform',
'load_data' => $loadData
After that we have created a form in an xml format, the next step is to load it. We have created a new file, called breed.php in models folder to deal with forms and data. In this file, on line 20, there is a method called getForm and in it, on line 26, we are actually loading the form. In its first argument, we are setting up the context. In this case, com_breed.breed would be the session variable which will store any data, entered through the form. The benefit of this is, suppose user has missed any required field while filling out the form, it will be redirected to the same form to fill this field. Now the data of other fields will be stored in this session which could be pulled out and fill the form. The next argument is the name of form we want to load. As we want to load breed.xml we are simply writing it as “breed” here. Next is the configuration array.
In the default.php template file, there comes our actual implementation of ordering the rows. For this purpose, as you know that in designing the database table section, we have created a field named “ordering” with int datatype, meant to hold only integer value. So, whenever you want to implement ordering, either in component backend or frontend list view, you must have to create a field named “ordering” with datatype int, in your corresponding database table.
On line 15 of above mentioned code, we are setting the value of $listOrder to be equal to a.ordering and then passing this value to $saveOrder. The reason is, when we are changing the order of a column, the records must be sorted according to the ordering column or field of the database table.
On line 20, we are using JHtml::_ class loader method and as I have discussed before that underscore(_) is a static method used by different Joomla classes for enabling a quick access to a number of methods in the sub packeage of respective class and in the JHtml case, these could be JHtmlGrid or JHtmlBehavior etc.
The first argument is the sortablelist.sortable, there is a call to JHtmlSortablelist class sortable method, located in /libraries/cms/html/sortablelist.php file. It is a utility class, meant to create a sortable table list. Thesecond argument is a reference to the id of our table on which we want to implement column ordering. Then there is areference to form and after that, there is the current sorting status and then, the url on which an ajax call will be made to update the ordering value of a specific record.
Then we have created our main ordering code from line 102 to 123 which is currently residing first, in the list which will actually create a drag icon in the first cell of each row. If the column is not sorted according to the ordering column, the ordering arrows will become inactive and it means that drag and drop ordering process would be deactivated.
I basically work in the CMS, like Joomla and WordPress and in framework like Laravel and have keen interest in developing mobile apps by utilizing hybrid technology. I also have experience working in AWS technology. In terms of CMS, I give Joomla the most value because I found it so much user freindly and my clients feel so much easy to manage their project in it.
Enjoy best web development services at an affordable price. Looking forward to build a good relationship and serve you better...
My name is Nohman Habib and I am a web developer with over 10 years of experience, programming in Joomla, Wordpress, WHMCS, vTiger and Hybrid Apps. My plan to start codingace.com is to share my experience and expertise with others. Here my basic area of focus is to post tutorials primarily on Joomla development, HTML5, CSS3 and PHP.