tags:

views:

379

answers:

2

I've been hacking together some basic Joomla 1.5 components and modules recently and always every time I get into it, I end up tearing my hair out because I simply do not understand how the MVC pattern works. Some examples of the problems I run into:

  • How does the view get access the model?
  • How do you switch to a different view?
  • How do you even include the correct file which defines the model?
  • etc.

I'm sure that there are very simple answers to all my questions: my main problem is that overall I don't feel the "documentation" is useful at all and definitely doesn't provide enough information about how to develop components/modules in the new MVC style. The API website is almost worse-than-useless since all it provides are class trees of the functions with virtually no comments at all. The docs website is targetted to administrators and core developers only.

Is there any useful source of information for web developers using Joomla 1.5?

+3  A: 

Although there are some articles about the core team mixed in, here is a link to the development category where you can get the most out of the docs site: http://docs.joomla.org/Category:Development And yes, the Joomla! Framework could use a LOT more in the way of documentation.

When you are using the controller class, the display() function is called by default if your task doesn't match any of the functions. This in turn checks the HTTP request for the view variable and displays the view with the same name. If no value for view is specified, you will get an error. The way to get around this is to define a display() function in your controller, then have it check the value of view, set it to a default value if unset, then call parent::display(). Here's one I've used in a recent project to display the mylist view:

function display()
{
    $view = JRequest::getVar('view', '');

    if ($view == '') {

        JRequest::setVar('view', 'mylist');

    }

    parent::display();
}

When your view is loaded, the model with the same name is also loaded. You can then access the model functions in your view class through $this->get(). For instance, if you have a function in your model named getPreferences(), you can call $this->get('preferences') to call that function.

jlleblanc
A: 

The MVC layout can be tricky when you first delve into it and by just looking at the Joomla team components.

I found that when I first designed my own component it was very confusing and complicated however I found an example component and basic tutorial for writing an MVC component in Joomla 1.5. You can find it at http://www.vojtechovsky.net/joomla/component-helloworld-2-create-tutorial-guide-en.html

I also then when onto to write 'The Simple META management suite' which follows the MVC guidelines and so if you wish to use it as an helper you can find it at www.aqsg.com.au

Hope that helps

privateace