PHP essentials

From Joomla! Documentation

Quill icon.png
Page Actively Being Edited!

This article is actively undergoing a major edit for a short while.
As a courtesy, please do not edit this page while this message is displayed. The user who added this notice will be listed in the page history. This message is intended to help reduce edit conflicts; please remove it between editing sessions to allow others to edit the page. If this page has not been edited for several hours, please remove this template, or replace it with {{underconstruction}} or {{incomplete}}.

PHP essentials[edit]


Many web designers and casual website owners are not conversant with the PHP language in which Joomla! is written and since Joomla! templates usually contain PHP statements it is necessary to understand at least a little of the language in order to be able to create or customise templates. This chunk will describe, in simple terms, how to use each aspect of PHP in the context of a Joomla! template. For example, a simple explanation of the PHP if-then-else syntax using extracts from a template for illustration.

The best resource to learn PHP is probably hands on experience and Joomla can provide that to you thanks to it's native PHP code. This can be overwhelming for people who have not programmed before. Though Joomla is easy enough to install with the help of the community and a little of your time you'll have people asking you to do their websites.

One place that has a nice short list if functions and examples is http://en.wikiversity.org/wiki/25_Essential_PHP_Functions which is good to get familiar with PHP. Though for an extensive function list, explanations, and examples go to http://www.php.net.

Once you have the basics of PHP you'll need to get the basics of the Joomla PHP syntax. Start by looking at some existing extensions and check out the code and also take a look at some these Tutorials about Joomla:

How to create a Joomla! Plugin

Developing a Model-View-Controller Component - Part 1

Developing a Model-View-Controller Component - Part 2 - Adding a Model

Developing a Model-View-Controller Component - Part 3 - Using the Database

Developing a Model-View-Controller Component - Part 4 - Creating an Administrator Interface

That will help you get familiar with some of the functions available within Joomla's system and what they do (using the API). Take paticular care to understand the MVC (model view control) setup.

Following is a very short introduction to PHP.

PHP Introduction[edit]

PHP is a scripting language and is designed primarily for producing dyanmic web pages. It is in general embedded into a HTML page with tags like <?php ... ?>. When such a page is passed on to the PHP engine, the engine translates the PHP tags into HTML and which can then be rendered by a browser. Further during translation the script may require to pull data from a database and thus a database is needed. So for creating PHP pages we require in general, the PHP engine, a database typically MySQL and finally the webserver which will co-ordinate these actions and forward the final HTML to the browser. These 3 components can be installed separately, however, for convinience we have packages like WAMP for windows, MAMP for mac and LAMP for Linux. Installing the packages is discussed next.

PHP Installation[edit]

The packages can be downloaded from Downloading WAMP. The instructions can be followed as given in the site and is pretty straightforward.

PHP Round trip[edit]

PHP Variable declaration and Data types[edit]

Basic operators and preceedence[edit]

Defining array Structures[edit]

String manipulation[edit]

Control expressions[edit]

Printing[edit]

Defining functions[edit]

Debugging[edit]

Handling forms[edit]

Super global variables[edit]

Database actions[edit]