Joomla MVC: How to Implement MVC Pattern in Joomla?



Joomla MVC Step by Step Tutorial: We have known Model View Controller (MVC) at previous tutorial. In this post, we will learn more how to apply MVC in Joomla conceptually. We must understand it before write line codes. How structure file when use MVC?

We still use hello component as study case. You can read about creating Hello Joomla Component in this site for refreshing before read this. Are you ready?

First, we glance over following structure file:

MVC structure file in Joomla

Model

We must create a folder named models. We know, model task connecting with data access. We will create 2 file: all and individual display. All means show all data/more than one data in a screen. Individual display means just one data will display according id that we choose. Create two file named "all.php" for fetch list data from table and "hello.php" for single data.

Model structure file in Joomla

View

As we know, the task of View is extracts data and formats it for presentation. For this job, we need structure file model like following screen:

View structure file in Joomla

Within all folder, created file named "view.html.php". Do it again within hello folder. Next, in each tmpl folder, created file named "default.php". So we get following structure:

view
+ all
    - view.html.php
    + tmpl
        - default.php
+ hello
    - view.html.php
    + tmpl
        - default.php

Controller

We just need a file for this job. Create file named "controller.php" within components/com_hello/.

Hope this post help you.



Series this article:
Joomla MVC: Introduction using Model View Controller
Joomla MVC: How to Implement MVC Pattern in Joomla?
Joomla MVC: How MVC Pattern Works in Joomla?
Joomla MVC: Updating hello.php As Component
Joomla MVC: Creating Controller Section
Joomla MVC: Creating Model that Show All Data
Joomla MVC: Creating View That Show All Data
Joomla MVC: Creating Default Template for View All
Joomla MVC: Creating Model that Show Individual Data
Joomla MVC: Creating View That Show a Data
Joomla MVC: Creating Default Template for View


Tag: joomla, MVC, component, module, pattern Category: PHP Framework Post : January 10th 2008 Read: 10,350 Bookmark and Share

blog comments powered by Disqus