Actions

Difference between revisions of "File Structure and Naming Conventions"

From Joomla! Documentation

(New page: ==Introduction== Components in Jooomla! 1.5 can now benefit from the flexibility and power of using Object Oriented Programming (OOP) practices. Most complex components will follow the Mo...)
 
Line 55: Line 55:
 
The file structure is exactly the same as in the /site folder. Note that the view, models, controllers etc. of the site and admin parts are completely separated, and have nothing to do with each other - the site part and the admin part can be thought of as two different components! A view in the /admin folder may have a counterpart with the same name in the /site folder, yet the two views have nothing in common but their name.
 
The file structure is exactly the same as in the /site folder. Note that the view, models, controllers etc. of the site and admin parts are completely separated, and have nothing to do with each other - the site part and the admin part can be thought of as two different components! A view in the /admin folder may have a counterpart with the same name in the /site folder, yet the two views have nothing in common but their name.
 
<noinclude>[[Category:Development]]</noinclude>
 
<noinclude>[[Category:Development]]</noinclude>
 +
[[Category:References]][[Category:Component Development]]

Revision as of 15:40, 29 September 2010

Contents

Introduction

Components in Jooomla! 1.5 can now benefit from the flexibility and power of using Object Oriented Programming (OOP) practices. Most complex components will follow the Model-View-Controller (MVC) design pattern. This pattern separates the data gathering (Model), presentation (View) and user interaction (Controller) activities of a component. Such separation allows for expanding or revising properties and methods of one section without requiring additional changes to the other sections. A useful set of tutorials demonstrating the process of creating an MVC component can be found here.

Throughout this article, {ComponentName} is used to represent the name of the component. Notice also that case is important. {componentname} will refer to the lowercase version of {ComponentName}, eg. "CamelCasedController" -> "camelcasedcontroller". Similarly, {ViewName} and {viewname}, {ModelName} and {modelname}, {ControllerName} and {controllername}.

File Structure

Installation package vs. actual file placement

A zipped installation package contains these two folders:

  • "site"
  • "admin"

The contents of "site" will correspond to the folder "/components/com_{componentname}" after the package is installed. The contents of "admin" will correspond to the folder "/administrator/components/com_{componentname}" after the package is installed. In this article, the former naming will be used.

/site

This folder keeps the files for the frontend part of the component.

site/{componentname}.php
This is the component's main file and entry point for the frontend part.
/site/controller.php
This file holds the default frontend controller, which is a class called "{ComponentName}Controller". This class must extend the base class "JController".
/site/views
This folder holds the different views for the component.
/site/views/{viewname}
This folder holds the files for the view {ViewName}.
/site/views/{viewname}/view.html.php
This file is the entry point for the view {ViewName}. It should declare the class {ComponentName}View{ViewName}. This class must extend the base class "JView".
/site/views/{viewname}/tmpl
This folder holds the template files for the view {ViewName}.
/site/views/{viewname}/tmpl/default.php
This is the default template for the view {ViewName}.
/site/models
This folder holds additional models, if needed by the application.
/site/models/{modelname}.php
This file holds the model class {ComponentName}Model{ModelName}. This class must extend the base class "JModel". Note that the view named {ViewName} will by default load a model called {ViewName} if it exists. Most models are named after the view they are intended to be used with.
/site/controllers
This folder holds additional controllers, if needed by the application.
/site/controllers/{controllername}.php
This file holds the controller class {ComponentName}Controller{ControllerName}. This class must extend the base class "JController".


/admin

The file structure is exactly the same as in the /site folder. Note that the view, models, controllers etc. of the site and admin parts are completely separated, and have nothing to do with each other - the site part and the admin part can be thought of as two different components! A view in the /admin folder may have a counterpart with the same name in the /site folder, yet the two views have nothing in common but their name.