6

I'm sure this sounds like a silly question but I am new to the MVC framework with Joomla and I haven't found any documentation that gives a clear definition. All I know so far is that the view.html.php file is entry file to the view.

I'm finding it difficult distinguishing between the two and I basically want to know how they work and how both files work together? Your feedback would be greatly appreciated.

7

It is just a best practice used in many frameworks. The idea is to keep your HTML code in files which are as simple as possible (meaning almost no PHP code) so that they are easy to maintain / reuse.

Let me explain:

You basically use the JView (view.html.php) class which contains the data you want to display. This class has a display() method which will automatically be called by Joomla when trying to render the view. The display method will almost auto-magically load the default.php file.

The view has a template (default.php) which has access to the properties of the view and has the responsibility of displaying HTML.

Basically the view has the responsibility of preparing the data for the template, so that the template does not have to do anything else but basic foreach loops or echoing variables.

So the template is as dumb as possible, the view is a bit smarter but not too smart as it should not contain any business logic.

Does it make sense?

2

View.html.php

Here, you can write your need functionality coding and The display method will almost auto-magically load the default.php file. .

Default.php

This will look like html page here, functionality result will be display in this page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.