Cherrycake
ExamplesGithub
version 2.x alpha
version 2.x alpha
  • Introduction
  • Status
  • Changelog
  • Migration
  • Architecture
    • Basics
    • Modules
    • Classes
    • Lifecycle
      • Deep lifecycle
    • Performance
    • Security
    • Patterns
      • Files structure
    • Items
    • Server requirements
  • Guide
    • Getting started
      • Skeleton start
      • Docker start
    • Modules guide
    • Classes guide
    • Actions guide
      • Complex actions
      • Variable path components
      • Accept GET or POST parameters
      • Getting the URL of an action
      • Cached actions
      • Brute force attacks
    • Patterns guide
      • Passing variables to a pattern
      • Nested patterns
      • Cached patterns
    • Cache guide
      • Time To Live
      • Using cache
      • Lists
      • Queues
      • Pools
    • Database guide
      • Basic queries
      • Prepared queries
      • Cached queries
      • Cache key naming
      • Removing queries from cache
    • Items guide
      • Item cache
      • Item lists
      • Items custom filters
      • Items custom ordering
      • Mixing filters and ordering
      • Items with relationships
      • Items cache
    • HtmlDocument guide
    • Css and Javascript guide
      • Modules injecting CSS and JavaScript
    • Session guide
    • Login guide
      • Creating a complete login workflow
    • Locale guide
      • Multilingual texts
      • Domain based site localization
    • Log guide
      • Loading Log events from the database
    • Stats guide
      • Stats events with additional dimensions
      • Loading Stats events from the database
    • Janitor guide
      • Janitor tasks configuration files
    • Command line interface
    • Debugging
  • Reference
    • Core modules
      • Actions
        • Actions methods
      • Browser
      • Cache
        • Cache methods
      • Css
        • Css methods
      • Database
      • Email
      • Errors
      • HtmlDocument
        • HtmlDocument methods
      • ItemAdmin
      • Janitor
        • Janitor methods
      • Javascript
        • Javascript methods
      • Locale
        • Locale methods
      • Log
        • Log methods
      • Login
        • Login methods
      • Output
        • Output methods
      • Patterns
        • Patterns methods
      • Security
        • Security methods
      • Session
        • Session methods
      • Stats
        • Stats methods
      • SystemLog
      • TableAdmin
      • Translation
      • Validate
    • Core classes
      • Action
        • Action methods
        • Action properties
      • AjaxResponseJson
      • BasicObject
        • BasicObject methods
      • CacheProvider
        • CacheProvider methods
      • Color
      • DatabaseProvider
        • DatabaseProvider methods
      • DatabaseResult
        • DatabaseResult methods
        • DatabaseResult properties
      • DatabaseRow
      • Engine
        • Engine methods
        • Engine properties
      • Gradient
      • Item
        • Item methods
        • Item properties
      • Items
        • Items methods
        • Items properties
      • Image
      • JanitorTask
        • JanitorTask methods
        • JanitorTask properties
      • LogEvent
        • LogEvent methods
        • LogEvent Properties
      • LogEvents
        • LogEvents methods
      • Module
        • Module methods
        • Module properties
      • Response
      • Request
        • Request methods
      • RequestParameter
        • RequestParameter methods
      • RequestPathComponent
        • RequestPathComponent methods
      • Result
      • StatsEvent
        • StatsEvent properties
      • StatsEvents
        • StatsEvents methods
      • SystemLogEvent
        • SystemLogEvent methods
        • SystemLogEvent properties
      • SystemLogEvents
        • SystemLogEvents methods
  • Code conventions
  • License
  • Extras
Powered by GitBook
On this page
  • __construct( setup )
  • __get( key )
  • __isset( key )
  • __set( key )
  • clearCache( fieldNames )
  • delete
  • loadFromData( data )
  • loadFromDatabaseRow( databaseRow )
  • loadFromId( id, fieldName, method )
  • loadInline( data )
  • update( data )

Was this helpful?

  1. Reference
  2. Core classes
  3. Item

Item methods

PreviousItemNextItem properties

Last updated 4 years ago

Was this helpful?

__construct( setup )

  • setup An optional hash array with the following possible setup keys:

    • loadMethod If specified, it loads the Item from the database using the given method, from one of the following available loading methods:

      • fromDatabaseRow Loads the item from the given object data passed in the databaseRow setup key.

      • fromId Loads the item identified by the id given in the id setup key.

      • fromData Loads the item using the data passed in the data setup key.

    • databaseRow The object to load the Item from when the fromDatabaseRow loadMethod is specified.

    • id The id on the database of the item to load, when the fromId loadMethod is specified.

    • data A hash array containing the data of the item to load, when the fromData loadMethod is specified, where each key is the field name, and its value the field value.

Throws: An Exception if the item could not be constructed or loaded.

__get( key )

Magic method to return the Item's data corresponding to the given key

  • key The key of the data to get, matches the database field name.

Returns: The data, or null if key didn't exist.

__isset( key )

Magic method to check whether the given key exists in the item.

  • key The key of the data to check, matches the database field name.

Returns: true if the key exists, false if not.

__set( key )

Magic method to set the item data with the given key to the given value

  • key The key of the data to set, matches the database field name.

  • value The value

clearCache( fieldNames )

Removes this Item from the cache. Can be overloaded if more additional things have to be cleared from cache in relation to the Item.

Returns: true on success, false on failure.

delete

Deletes this item from the database.

Returns: true on success, false on failure.

loadFromData( data )

Loads the item with the given data.

Returns: true on success, false on failure.

loadFromDatabaseRow( databaseRow )

Returns: true on success, false on failure.

loadFromId( id, fieldName, method )

Loads the item identified by the given id from the database.

  • id The id

    • queryDatabaseCache Load the item from the database using cache.

    • queryDatabase Load the item from the database without using cache.

Returns: true if the item was found and loaded successfully, false otherwise.

loadInline( data )

Loads the item when no loadMethod has been provided on construction. Intended to be overloaded when needed.

  • data A hash array with the data. Default: false

Returns: true on success, false on error.

update( data )

Updates the data on the database for this Item with the passed data, or with the data stored on the object if no data is passed.

  • data An optional hash array where each key is the field name to update, and each value the new data to store on that field for this item. If not passed or left to false, the current data stored in the object is used. Default: false

Returns: true on success, false on failure.

fieldNames An optional array of field names that have been used to query items by index, so those queries will be cleared from cache. and other field names commonly used by this object are automatically added to this array and cleared from cache.

data A hash array containing the data of the item, where each key is the field name as defined in the property, and each value is the field value.

Loads the item from the given .

databaseRow A object containing the data of the item.

fieldName The name of the field containing the id, as defined in the property. Should be a field that uniquely identifies a row on the database.

method The loading method to use. If not specified, it uses the default . One of the following values:

For multilanguage fields, a hash array must be passed as the value, where each key is one of the available constants and the value is the value in that language. If a non-array value is passed the currently detected language will be used.

DatabaseRow
DatabaseRow
DatabaseRow
DatabaseRow
idFieldName
Item::$fields
Item::$fields
Item::$loadFromIdMethod
LANGUAGE_?