Joomla get('Items') and how it works

dingerkingh picture dingerkingh · Mar 5, 2012 · Viewed 19.6k times · Source

I am looking at line 34 of /administrator/components/com_contact/views/contacts/view.html.php where is says $this->items = $this->get('Items'); What I don't understand is how that is actually calling the protected function getListQuery() on line 123 of /administrator/components/com_contact/models/contacts.php

There are also some other things I don't understand how are working... like

$this->pagination   = $this->get('Pagination');
$this->state        = $this->get('State');

What are these calling? I looked at the documentation for "get()" but it doesn't say what these are actually calling because I don't see any methods called getPagination, getState or getItems... It appears the get('Items') is somehow magically calling getListQuery().

Answer

Craig picture Craig · Mar 6, 2012

I'm presuming 1.7/2.5+ here...

In Joomla!'s MVC the view contacts (ContactViewContacts which extends JView) automatically loads the model contacts (or in J! terminology ContactModelContacts) which as a class extends JModelList.

The get() looks in the view to get data from a registered model or a property of the view.

So;

$this->items = $this->get('Items');

is actually a call to the model ContactModelContacts which has a matching getItems() in it's parent.

The model file com_contact/models/contacts.php doesn't implement it's own getItems(), so the getItems() from the JModelList class is used (found in /libraries/joomla/application/component/modellist.php).

This in turn calls getListQuery() - no magic just inheritance.

The $this->get('Pagination') is doing the same thing, ie. accessing the implementation in the models parent.

The $this->get('State') is probably going all the way back to the JModel implementation.