Introduction In the first two parts, we showed how to make a simple component-based scheme mvc. We had a simple view that retrieves data from the model (it was created in the second part). In this part we will work only with the model. Instead, the data hardcoded in the model, we'll get them from a database table with a class JDatabase. Retrieving Data Now our model has only one method: getGreeting (). This is a very simple example – all that he does it returns the hardcoded code. To make our example more interesting, we'll upload a greeting from the database. Later we will show how to create a sql file and add the code in the xml file to install the component was created and populated the table you want.
While we just modify the function to return the greeting so that she got it from the database. First you need to get a reference to baze. Starting with Joomla, the use of databases is a common procedure. Connection to the database already exists, so no need to create their own. Link to an existing database can be obtained as follows: $ db = & JFactory:: getDBO (); Jfactory – this is a static class that is used to obtain links to many of the object system. More information about this class can be obtained here. Method name (getDBO) is derived from the get DatBase Object to make it easy to remember. To get the record from the database we need to do two steps: 1.