16

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().

dingerkingh
  • 448
  • 1
  • 6
  • 16

1 Answers1

35

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.

Craig
  • 9,335
  • 2
  • 34
  • 38
  • 1
    Man do I feel like a moron... That makes too much sense. I guess I have just never seen a Inherited method get called and then call a subclass method. I think I typed that correctly. Either way - THANK YOU! – dingerkingh Mar 06 '12 at 11:40
  • 9
    Joomla component developer tutorial is responsible for this mess. I waste big time wandering about this mess(I imagined this would be the way but in the tutorial it was not there in 1.5 or 2.5). Thank you very much for the answer. – Ruwantha Jun 03 '13 at 10:23
  • 4
    I'd like to add that if anyone, including Ruwantha, is unhappy with any of the Joomla documentation,you can contribute to improving it. Joomla is an all volunteer project and it takes everyone's help to make it better. – betweenbrain Aug 29 '14 at 13:17
  • One quick question. Do we have set() method also just like get()? – Suyash Dixit Oct 04 '14 at 21:02