Book Image

Mastering Joomla! 1.5 Extension and Framework Development Second Edition

Book Image

Mastering Joomla! 1.5 Extension and Framework Development Second Edition

Overview of this book

Joomla! is one of the world’s top open source content management systems, which enables you to build websites and powerful online applications. Out of the box, Joomla! does a great job of managing the content needed to enhance the functionality of your website. But for many people, the true power of Joomla! lies in its application framework that makes it possible for thousands of developers around the world to create powerful add-ons and extensions. This book will guide you through the complexities of implementing add-ons, components, modules, and plugins in Joomla! 1.5. If you feel that you’ve mastered the basics of creating Joomla! extensions, then this book will take you to the next level. Packed with expert advice on all aspects of programming with Joomla!, this book is an invaluable reference guide you will turn to again and again for your Joomla! development tasks. The book starts by explaining the structure and design of the Joomla! Framework. Then we move on to extending and storing data in standard fields and dealing with multilingual requirements. Further, you will discover best practices, design, and coding methods for Joomla! components, modules, plugins, and other extensions. Along the way, you will actually design and create a component, module, and plugin that work together to add functionality to the Joomla! framework. You will also learn about customizing the page output using JavaScript effects, making use of Web Services from within Joomla! and ensuring that your code is secure and error-free. You will discover how to easily create sophisticated extensions that are robust, user-friendly, and professional by taking advantage of the many libraries and utilities provided by the Joomla! framework. A comprehensive, up-to-date reference to the Joomla! Framework API is also included in the book. Finally, we will discuss advanced methods for rendering your extensions more robust, secure, and professional.
Table of Contents (18 chapters)
Mastering Joomla! 1.5 Extension and Framework Development
Credits
About the Author
About the Reviewer
Preface

JModel


abstract, extends JObject , located in / joomla/application/component/model.php

This base class acts as a Factory class for model classes that use the MVC implementation. For further information on using the JModel class refer to Chapter 5, Component Design.

Properties

JDatabase $_db

Reference to the database connection

string $_name

Model base name

JObject $_state

Model state

Inherited properties

Inherited from JObject:

  • JObject::$_errors

Inherited methods

Inherited from JObject:

  • JObject::JObject()

  • JObject::__construct()

  • JObject::get()

  • JObject::getError()

  • JObject::getErrors()

  • JObject::getProperties()

  • JObject::getPublicProperties()

  • JObject::set()

  • JObject::setError()

  • JObject::setProperties()

  • JObject::toString()

Methods

Constructor __construct

Class constructor. Builds a new JModel object. The associative array $config can contain the keys name and table_path. name is transposed to the model name; if name is not specified the name will be extracted from the name of the class. This will only work if the name of the class is in the format optionalPrefixModelSomeName. table_path will be added to the JTable include paths. If $table_path is not specified, but JPATH_COMPONENT_ADMINISTRATOR is defined, then the path JPATH_COMPONENT_ADMINISTRATOR.DS.'tables' will be added. Redefinition of JObject::__construct(); overridden in descendant classes.

JModel __construct([$config = array()])

  • array $config: An associative array of configuration options

addIncludePath

This static method adds a new path or set of paths used to find JModel classes. $path can be a string or an array of strings.

array addIncludePath([$path = ''])

  • mixed $path: The path or an array of paths to add

  • array: Returns an array of paths to search for JModel subclasses

addTablePath

This static method adds a new path or set of paths used to find JTable classes. $path can be a string or an array of strings. This method is a pass-through method for JTable::addIncludePath().

array addTablePath([$path = ''])

  • mixed $path: The path or an array of paths to add

  • array: Returns an array of paths

getDBO

This method returns a reference to the global JDatabase connection.

JDatabase &getDBO()

  • object: Returns a reference to the global JDatabase connection.

getInstance

This static method returns a reference to a new instance of a JModel subclass object. If the class cannot be found it returns false.

mixed &getInstance($type, [$prefix = ''], [$config = array()])

  • string $type: The model type to instantiate

  • string $prefix: The prefix for the model class name; optional

  • array $config: The configuration array for the model; optional

  • mixed: Returns a reference to a new JModel object or false on failure

getName

This method returns the name of the model. The model name by default is parsed using the class name, or it can be set by passing a $config['name'] in the class constructor.

string getName()

  • string: Returns the name of the model

getState

This method returns the model state variables. If $property is not specified a complete copy of the model's state object is returned.

mixed getState([string $property = null])

  • string $property: Optional property name

  • mixed: Returns a state property or copy of the state property object

getTable

This method returns an instance of a JTable subclass object. If $name is not specified, then the model name will be used. The parameters are concatenated to create the class name, in the form $prefix.$name. If the class is not present, the paths defined in JTable will be searched for a file named $prefix.$name.'.php' where the class should reside.

JTable &getTable([$name = ''], [$prefix = 'Table'], [$options = array()])

  • string $name: Optional table name

  • string $prefix: Optional class prefix

  • array $options: Optional configuration array for the model

  • object: Returns a reference to a new instance of a JTable subclass object

setDBO

This method sets the reference to the global JDatabase connection.

void setDBO(&$db)

  • void: No return type

setState

This method sets a user state property.

mixed setState($property, [$value = null])

  • string $property: The name of the property

  • mixed $value: The value of the property to set

  • mixe d: Returns the previous value of the state property

_createFileName

This private method gets the name of the file where a class should be located. $parts must include the key 'name'. $type should always be 'model'.

string _createFileName($type, [$parts = array()])

  • string $type: The type of file (only accepts 'model'

  • array $parts: An associative array of name parts

  • string: Returns the name of the file

_createTable

This private method is used by getTable() to create a new instance of a JTable subclass object. It returns null or an error on failure.

mixed &_createTable($name, [$prefix = 'Table'], [$config = array()])

  • string $name: The name of the JTable

  • string $prefix: The class prefix, normally Table or JTable

  • array $config: An associative array of configuration information

  • mixed: Returns a reference to a new JTable object or null upon failure

_getList

This private method executes a query and gets a reference to an array of resultant objects.

array &_getList($query, $limitstart = 0, $limit = 0)

  • string $query: The query to execute

  • integer $limitstart: The start record

  • integer $limit: The maximum number of records

  • array: Returns an array of objects as a result of the query

_getListCount

This private method returns the number of results obtained from the query. This method should be used cautiously as it causes the query to be executed. If possible consider using $db‑>getNumRows() directly after &_getList(); this prevents the query from being executed twice.

integer &_getListCount($query)

  • string $query: The query to execute

  • integer: Returns the count of records from the query