Developing a Model-View-Controller Component for Joomla Part 2

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Introduction to Rails.
Advertisements

Programmer-defined classes Part 2. Topics Returning objects from methods The this keyword Overloading methods Class methods Packaging classes Javadoc.
ASP.NET Programming with C# and SQL Server First Edition
Dependency Injection and Model-View-Controller. Overview Inversion of Control Model-View-Controller.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Lecture Roger Sutton CO530 Automation Tools 5: Class Libraries and Assemblies 1.
You gotta be cool. Introduction to Classes, Objects and Strings Introduction Defining a Class with a Member Function Defining a Member Function with a.
CSCI 6962: Server-side Design and Programming Web Services.
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
Computers and Scientific Thinking David Reed, Creighton University Functions and Libraries 1.
Objective At the conclusion of this chapter you will be able to:
Interfaces About Interfaces Interfaces and abstract classes provide more structured way to separate interface from implementation
MVC WITH CODEIGNITER Presented By Bhanu Priya.
Working with Packages BCIS 3680 Enterprise Programming.
1 UMBC CMSC 104, Section Fall 2002 Functions, Part 1 of 3 Topics Top-down Design The Function Concept Using Predefined Functions Programmer-Defined.
Unit 3 Lesson 5 Strings and the String Class Mr. Dave Clausen (modifications from the textbook)
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Entity Framework Database Connection with ASP Notes from started/getting-started-with-ef-using-mvc/creating-an-
Introduction to Inversion Of Control (IOC). IOC Definition (based on Wikipedia)  Consider the way in which an object obtains references to its dependencies.
CUSTOM OOP. SYNTAX OF A CLASS DEFINITION Class definitions (descriptions) look like this: class ClassName { Descriptions of the instance variables and.
Bootstrap Tutorial Overview Objective Learn how to use the bootstrap for configuring the system. Requirements Installed Version of.
1 Using MVC 6. MVC vs. ASP Web Forms Both run under ASP.NET Can coexist In Web Forms, browser requests page. xxx.aspx and xxx.aspx.cs on the server Page.
Jim Fawcett CSE686 – Internet Programming Spring 2014
Data Virtualization Demoette… Packaged Query Single Select Option
Visit for more Learning Resources
User-Written Functions
Custom Profile Options
Data Virtualization Tutorial: Introduction to SQL Script
USING PYTHON to Automate data management tasks
Jim Fawcett CSE686 – Internet Programming Spring 2012
Programmer: Roman Martushev
Introduction Purpose Objectives Content Learning Time
Play Framework: Introduction
Sequences and Iterators
Introduction to CodeIgniter (CI)
Activities and Intents
1-Introduction (Computing the image histogram).
Separate Assembly allows a program to be built from modules rather than a single source file assembler linker source file.
PHP / MySQL Introduction
Using Procedures and Exception Handling
SQL – Application Persistence Design Patterns
Separate Compilation and Namespaces
Machine Independent Features
Sequences Objectives:
Week 9 – Lesson 1 Arrays – Character Strings
Copyright ©2012 by Pearson Education, Inc. All rights reserved
This presentation document has been prepared by Vault Intelligence Limited (“Vault") and is intended for off line demonstration, presentation and educational.
Chapter 15 Introduction to Rails.
Object Oriented Programming in java
Developing a Model-View-Controller Component for Joomla Part 3
This presentation document has been prepared by Vault Intelligence Limited (“Vault") and is intended for off line demonstration, presentation and educational.
This presentation document has been prepared by Vault Intelligence Limited (“Vault") and is intended for off line demonstration, presentation and educational.
Smart Integration Express
Programs and Classes A program is made up from classes
Tonga Institute of Higher Education
Developing a Model-View-Controller Component for Joomla
This presentation document has been prepared by Vault Intelligence Limited (“Vault") and is intended for off line demonstration, presentation and educational.
This presentation document has been prepared by Vault Intelligence Limited (“Vault") and is intended for off line demonstration, presentation and educational.
Java Tutorial – Application Building
Machine Independent Assembler Features
CodePainter Revolution Trainer Course
Rational Publishing Engine RQM Multi Level Report Tutorial
Machine Independent Assembler Features
ASP.NET and Model View Control
Preference Activity class
Sequences Objectives:
Plug-In Architecture Pattern
This presentation document has been prepared by Vault Intelligence Limited (“Vault") and is intended for off line demonstration, presentation and educational.
Introduction to Classes and Objects
Presentation transcript:

Developing a Model-View-Controller Component for Joomla Part 2

Introduction In the first Part of this series, creating a simple view-controller component using the Joomla! 1.5 CMS framework was demonstrated. In the first part, the greeting was hardcoded into the view. This doesn't follow the MVC pattern exactly because the view is intended to only display the data, and not contain it. In this second part of the series we will demonstrate how to move this out of the view and into a model. In future tutorials we will demonstrate the power and flexibility that this design pattern provides.

Creating the Model The concept of model gets its name because this class is intended to represent (or 'model') some entity. In our case, our first model will represent a 'hello', or a greeting. This is in line with our design thus far, because we have one view ('hello'), which is a view of our greeting. The naming convention for models in the Joomla! framework is that the class name starts with the name of the component (in our case 'hello'), followed by 'model', followed by the model name. Therefore, our model class is called HelloModelHello. At this point, we will only model one behaviour of our hello, and that is retrieving the greeting. We will thus have one method, called getGreeting(). It will simply return the string 'Hello, World!'.

The code for the model at site/models/hello.php

The code for the model at site/models/hello.php You will notice a line that starts with jimport. The jimport function is used to load files from the Joomla! framework that are required for our component. This particular statement will load the file /libraries/joomla/application/component/model.php. The '.'s are used as directory separators and the last part is the name of the file to load. All files are loaded relative to the libraries directory. This particular file contains the class definition for the JModel class, which is necessary because our model extends this class. Now that we have created our model, we must modify our view so that it uses it to obtain the greeting.

Using the Model The Joomla! framework is setup in such a way that the controller will automatically load the model that has the same name as the view and will push it into the view. Since our view is called 'Hello', our 'Hello' model will automatically be loaded and pushed into the view. Therefore, we can easily retrieve a reference to our model using the JView::getModel() method. (If the model had not followed this convention, we could have passed the model name, as a parameter, to JView::getModel())

Using the Model Our previous view code contained the lines: To take advantage of our model, we change this line to:

Adding the File to the Package All that remains is to add an entry to the XML file so that our new model will be copied. The Joomla! framework will look for our model in the models directory, so the entry for this file will look like (it should be added to the site section): <filename>models/hello.php</filename>