Create components for Joomla! - Managing the front end

 Please note: this page is under update!
Contents here may refer both to current or previous version of Joomla! component builder, and contents may be related to Joomla! 1.5 version.


Develop MVC component for Joomla! 3.x Front - End Side

Now you have to add an item to your menu to access the component from the front end, we will use the "View for booklist list" view in our example. Of course we have also to add some authors, editors and book to see the component to work.

From the front end point of view, the entry point's work is simple, in fact, normally, access happens via a menu item, the view is already defined in the URL created by Joomla!.

For example, the URL involved, we suppose SEF is off, means that Joomla! looks mybooks.php in the folder /components/com_mybooks. On the basis of the parameter view, in the url, this entry point loads the appropiate controller and executes the right task, default task is display. The view \views\booklist\view.html.php is then executed.

Within the last file we have, among others, the following lines of code:

function display ($tpl = null) (
 $data = $this->get ('Data');
 $this->assignRef( 'data', $data);
 parent::display ($ tpl);

The header of the method display() include the optional parameter $tpl, Attention! is not the name of the template to load, but the name of the sub-template!

  1. The code $data = $this->get('Data') invokes the method getData() in the file /models/mybooklist.php, this method makes the query on the db and returns a recordset as an array of object,s in the standard Joomla!.
  2. the code $this->assignRef( 'data', $data) creates the property $this->data within the class MybooksViewBooklist so that such information is easily accessible from the template.
  3. the code parent::display($tpl) invokes and executes the file /components/com_mybookst/views/booklist/tmpl/default.php which displays the contents of the recordset.

In the file /components/com_mybooks/views/booklist/tmpl/default.php you will find a code like this:

<?php foreach($this->data as $dataItem): ?>
    $link = JRoute::_( "index.php?option=com_ccat&amp;view=ccatbrand&amp;brand_id={$dataItem->id}" );
  <td class="cb_fieldDiv jcb_fieldValue" >
    <a href="/<?php echo $link; ?>"><?php echo $dataItem->title; ?></a>
<?php endforeach; ?> 

The foreach loop iterates through all the records retrieved from the method getData(), in the model, and assign them to $this->data from view with assignRef().

the code $link = JRoute::_("...") creates the URL to see the single record, in the following lines we see how to use this URL (<a href ="<?php echo $ link;?> ">) And how to retrieve data from the record set ($DataItem->title, where "title" is the name of the field in the table), Joomla!Component Builder will return all the fields of the reference table, it's to you to decide which to show, and write the code for generating the best layout.

As for the display of single record, the process is practically the same, obviously in the template there is no foreach: simple, no?


The component builder, on front end side, does not support any operation on the data except for the visualization of a grid of data. If you need to operate on data you have to write the proper controller. These kind of operations will be implemented in the future.


previous & more interesting: manage the back end


-2 #1 Guest 2013-09-26 06:25
Hello sir, I wont to make a registation form component using MVC and display at frantend and store it in the backend table. so, if you have any this type of tutorial or any suggestion then please reply me.

Aggiungi commento

Please note: URL in text are not linked and user's site address is only for internal use and is not published.

Comments are human checked. All spam will be removed, so don't waste your time and, especially, mine!

Codice di sicurezza

L'estate si avvicina hai già trovato l'albergo per le vacanze? cerca un albergo al mare o un hotel in montagna ove trascorrere le tue vacanze.