BaseDatabaseModel

Extends BaseModel Implements DatabaseModelInterface, DispatcherAwareInterface, CurrentUserInterface, CacheControllerFactoryAwareInterface, DatabaseAwareInterface

Base class for a database aware Joomla Model

abstract

Acts as a Factory class for application specific objects and provides many supporting API functions.

since

2.5.5

package

Joomla CMS

Methods

__construct

Constructor

__construct(mixed||string|int config = [], \Joomla\CMS\MVC\Factory\MVCFactoryInterface factory = null) : 
since

3.0

throws

Exception

Arguments

config

array<string|int, mixed>An array of configuration options (name, state, dbo, table_path, ignore_request).

factory

MVCFactoryInterface|nullThe factory.

Response

mixed

__get

Proxy for _db variable.

__get( name) : 
deprecated
since

4.2.0

deprecated

4.3 will be removed in 6.0 Use getDatabase() instead of directly accessing _db

Arguments

name

stringThe name of the element

Response

mixedThe value of the element if set, null otherwise

__toString

Magic method to convert the object to a string gracefully.

__toString() : 
inherited deprecated
since

1.7.0

deprecated

4.3 will be removed in 6.0 Classes should provide their own __toString() implementation.

Response

stringThe classname.

_createFileName

Create the filename for a resource

_createFileName( type, mixed||string|int parts = []) : 
inherited static deprecated
since

3.0

deprecated

4.3 will be removed in 6.0 Will be removed without replacement

Arguments

type

stringThe resource type to create the filename for.

parts

array<string|int, mixed>An associative array of filename information.

Response

stringThe filename

_createTable

Method to load and return a table object.

_createTable( name,  prefix = 'Table', mixed||string|int config = []) : \Joomla\CMS\Table\Table|bool
since

3.0

see JTable::getInstance()

Arguments

name

stringThe name of the view

prefix

stringThe class prefix. Optional.

config

array<string|int, mixed>Configuration settings to pass to Table::getInstance

Response

Table|boolTable object or boolean false if failed

_getList

Gets an array of objects from the results of database query.

_getList(\Joomla\Database\DatabaseQuery|string query,  limitstart,  limit) : object||string|int
since

3.0

throws

RuntimeException

Arguments

query

DatabaseQuery|stringThe query.

limitstart

intOffset.

limit

intThe number of records.

Response

array<string|int, object>An array of results.

_getListCount

Returns a record count for the query.

_getListCount(\Joomla\Database\DatabaseQuery|string query) : 

Note: Current implementation of this method assumes that getListQuery() returns a set of unique rows, thus it uses SELECT COUNT(*) to count the rows. In cases that getListQuery() uses DISTINCT then either this method must be overridden by a custom implementation at the derived Model Class or a GROUP BY clause should be used to make the set unique.

since

3.0

Arguments

query

DatabaseQuery|stringThe query.

Response

intNumber of rows for query.

addIncludePath

Add a directory where \JModelLegacy should search for models. You may either pass a string or an array of directories.

addIncludePath( path = '',  prefix = '') : mixed||string|int
inherited static deprecated
since

3.0

deprecated

4.3 will be removed in 6.0 Will be removed without replacement. Get the model through the MVCFactory + namespace instead

see

Arguments

path

mixedA path or array[sting] of paths to search.

prefix

stringA prefix for models.

Response

array<string|int, mixed>An array with directory elements. If prefix is equal to '', all directories are returned.

addTablePath

Adds to the stack of model table paths in LIFO order.

addTablePath( path) : 
inherited static deprecated
since

3.0

deprecated

4.3 will be removed in 6.0 Will be removed without replacement. Get the model through the MVCFactory instead

Arguments

path

mixedThe directory as a string or directories as an array to add.

Response

void

bootComponent

Boots the component with the given name.

bootComponent( component) : \Joomla\CMS\Extension\ComponentInterface
since

4.0.0

Arguments

component

stringThe component name, eg. com_content.

Response

ComponentInterfaceThe service container

cleanCache

Clean the cache

cleanCache( group = null) : 
since

3.0

Arguments

group

stringThe cache group

Response

void

createModelFromComponent

Returns a Model object by loading the component from the prefix.

createModelFromComponent( type,  prefix = '', mixed||string|int config = []) : \Joomla\CMS\MVC\Model\ModelInterface|null
inherited static deprecated
since

4.0.0

deprecated

4.3 will be removed in 6.0 Will be removed without replacement

Arguments

type

stringThe model type to instantiate

prefix

stringPrefix for the model class name. Optional.

config

array<string|int, mixed>Configuration array for model. Optional.

Response

ModelInterface|nullA ModelInterface instance or null on failure

def

Sets a default value if not already assigned

def( property,  default = null) : 
inherited deprecated
since

1.7.0

deprecated

4.3.0 will be removed in 6.0 Defining dynamic properties should not be used anymore

Arguments

property

stringThe name of the property.

default

mixedThe default value.

Response

mixed

dispatchEvent

Dispatches the given event on the internal dispatcher, does a fallback to the global one.

dispatchEvent(\Joomla\Event\EventInterface event) : 
deprecated
since

4.1.0

deprecated

4.4 will be removed in 6.0. Use $this->getDispatcher() directly.

Arguments

event

EventInterfaceThe event

Response

void

get

Returns a property of the object or the default value if the property is not set.

get( property,  default = null) : 
inherited deprecated
since

1.7.0

see CMSObject::getProperties()
deprecated

4.3.0 will be removed in 6.0 Create a proper getter function for the property

Arguments

property

stringThe name of the property.

default

mixedThe default value.

Response

mixedThe value of the property.

getCacheControllerFactory

Get the CacheControllerFactoryInterface.

getCacheControllerFactory() : \Joomla\CMS\Cache\CacheControllerFactoryInterface
inherited
since

4.2.0

Response

CacheControllerFactoryInterface

getCurrentUser

Returns the current user, if none is set the identity of the global app is returned. This will change in 6.0 and an empty user will be returned.

getCurrentUser() : \Joomla\CMS\User\User
inherited
since

4.2.0

Response

User

getDbo

Get the database driver.

getDbo() : \Joomla\Database\DatabaseInterface
deprecated
since

4.2.0

throws

UnexpectedValueException

deprecated

4.3 will be removed in 6.0 Use getDatabase() instead Example: $model->getDatabase();

Response

DatabaseInterfaceThe database driver.

getDispatcher

Get the event dispatcher.

getDispatcher() : \Joomla\Event\DispatcherInterface

The override was made to keep a backward compatibility for legacy component. TODO: Remove the override in 6.0

since

4.4.0

throws

UnexpectedValueExceptionMay be thrown if the dispatcher has not been set.

Response

DispatcherInterface

getError

Get the most recent error message.

getError( i = null,  toString = true) : 
inherited deprecated
since

1.7.0

deprecated

3.1.4 will be removed in 6.0 Will be removed without replacement Catch thrown Exceptions instead of getError

Arguments

i

intOption error index.

toString

boolIndicates if Exception objects should return their error message.

Response

stringError message

getErrors

Return all errors, if any.

getErrors() : mixed||string|int
inherited deprecated
since

1.7.0

deprecated

3.1.4 will be removed in 6.0 Will be removed without replacement Catch thrown Exceptions instead of getErrors

Response

array<string|int, mixed>Array of error messages.

getInstance

Returns a Model object, always creating it

getInstance( type,  prefix = '', mixed||string|int config = []) : self|bool
inherited static deprecated
since

3.0

deprecated

4.3 will be removed in 6.0 Will be removed without replacement. Get the model through the MVCFactory instead Example: Factory::getApplication->bootComponent('com_xxx')->getMVCFactory()->createModel($type, $prefix, $config);

Arguments

type

stringThe model type to instantiate

prefix

stringPrefix for the model class name. Optional.

config

array<string|int, mixed>Configuration array for model. Optional.

Response

self|boolA \JModelLegacy instance or false on failure

getMVCFactory

Returns the MVC factory.

getMVCFactory() : \Joomla\CMS\MVC\Factory\MVCFactoryInterface
inherited
since

4.0.0

throws

UnexpectedValueException

Response

MVCFactoryInterface

getName

Method to get the model name

getName() : 
inherited

The model name. By default parsed using the classname or it can be set by passing a $config['name'] in the class constructor

since

4.0.0

throws

Exception

Response

stringThe name of the model

getProperties

Returns an associative array of object properties.

getProperties( public = true) : mixed||string|int
inherited deprecated
since

1.7.0

see CMSObject::get()
deprecated

4.3.0 will be removed in 6.0 Create a proper getter function for the property

Arguments

public

boolIf true, returns only the public properties.

Response

array<string|int, mixed>

getState

Method to get state variables.

getState( property = null,  default = null) : 
inherited
since

4.0.0

Arguments

property

stringOptional parameter name

default

mixedOptional default value

Response

mixedThe property where specified, the state object where omitted

getTable

Method to get a table object, load it if necessary.

getTable( name = '',  prefix = '', mixed||string|int options = []) : \Joomla\CMS\Table\Table
since

3.0

throws

Exception

Arguments

name

stringThe table name. Optional.

prefix

stringThe class prefix. Optional.

options

array<string|int, mixed>Configuration array for model. Optional.

Response

TableA Table object

isCheckedOut

Method to check if the given record is checked out by the current user

isCheckedOut(\stdClass item) : 

Arguments

item

stdClassThe record to check

Response

bool

populateState

Method to auto-populate the state.

populateState() : 
inherited

This method should only be called once per instantiation and is designed to be called on the first call to the getState() method unless the configuration flag to ignore the request is set.

note

Calling getState in this method will result in recursion.

since

4.0.0

Response

void

set

Modifies a property of the object, creating it if it does not already exist.

set( property,  value = null) : 
inherited deprecated
since

1.7.0

deprecated

4.3.0 will be removed in 6.0 Create a proper setter function for the property

Arguments

property

stringThe name of the property.

value

mixedThe value of the property to set.

Response

mixedPrevious value of the property.

setCacheControllerFactory

Set the cache controller factory to use.

setCacheControllerFactory(\Joomla\CMS\Cache\CacheControllerFactoryInterface cacheControllerFactory = null) : 
inherited
since

4.2.0

Arguments

cacheControllerFactory

CacheControllerFactoryInterfaceThe cache controller factory to use.

Response

void

setCurrentUser

Sets the current user.

setCurrentUser(\Joomla\CMS\User\User currentUser) : 
inherited
since

4.2.0

Arguments

currentUser

UserThe current user object

Response

void

setDbo

Set the database driver.

setDbo(\Joomla\Database\DatabaseInterface db = null) : 
deprecated
since

4.2.0

deprecated

4.3 will be removed in 6.0 Use setDatabase() instead Example: $model->setDatabase($db);

Arguments

db

DatabaseInterface|nullThe database driver.

Response

void

setError

Add an error message.

setError( error) : 
inherited deprecated
since

1.7.0

deprecated

3.1.4 will be removed in 6.0 Will be removed without replacement Throw an Exception instead of using setError

Arguments

error

stringError message.

Response

void

setMVCFactory

Set the MVC factory.

setMVCFactory(\Joomla\CMS\MVC\Factory\MVCFactoryInterface mvcFactory) : 
inherited
since

4.0.0

Arguments

mvcFactory

MVCFactoryInterfaceThe MVC factory

Response

void

setProperties

Set the object properties based on a named array/hash.

setProperties( properties) : 
inherited deprecated
since

1.7.0

see CMSObject::set()
deprecated

4.3.0 will be removed in 6.0 Create a proper setter function for the property

Arguments

properties

mixedEither an associative array or another object.

Response

bool

setState

Method to set state variables.

setState( property,  value = null) : 
inherited
since

4.0.0

Arguments

property

stringThe name of the property

value

mixedThe value of the property to set or null

Response

mixedThe previous value of the property or null if not set

Properties

_errors

An array of error messages or Exception objects.

inherited deprecated
since

1.7.0

deprecated

3.1.4 JError has been deprecated

Type(s)

array<string|int, mixed>

__state_set

Indicates if the internal state has been set

inherited
since

4.0.0

Type(s)

bool

state

A state object

inherited
since

4.0.0

Type(s)

CMSObject

name

The model (base) name

inherited
since

4.0.0

Type(s)

string

paths

The include paths

inherited static
since

4.0.0

Type(s)

array<string|int, mixed>

cacheControllerFactory

CacheControllerFactoryInterface

inherited
since

4.2.0

Type(s)

CacheControllerFactoryInterface

currentUser

The current user object.

inherited
since

4.2.0

Type(s)

User

mvcFactory

The mvc factory.

inherited
since

4.0.0

Type(s)

MVCFactoryInterface

option

The URL option for the component.

since

3.0

Type(s)

string

event_clean_cache

The event to trigger when cleaning cache.

since

3.0

Type(s)

string