Model_Base Class Reference

Inherited by Model.

List of all members.

Public Member Functions

 Model_Base ()
 depend ($model)
import_plugin ($name)
 validate_for_insert ($data)
 validate_for_update ($data)
 validate ($data, $is_update=false)
 purify ($data)
 sanitize ($data)
 create ()
 get ($id)
 invalidate ($id)
 get_record ($id)
 get_bare ($id)
 get_multi ($ids, $ignore_empty=true)
 get_value ($id, $column)
 get_by ($column, $value)
 get_all_by ($column, $value)
 get_all ()
 get_or_404 ($id)
 delete ($id)
 insert ($data)
 update ($data)
 list_params ()
 __call ($name, $args)
 save ($data)
 load ($id)
 create_record ()
 enum_schema ()

Public Attributes

 $db = null
 $web = null
 $cache = null
 $depends = null
 $plugins = null
 $context = null
 $table = null
 $pk = 'id'
 $default_sort = 'id'
 $per_page = 50
 $enable_cache = false
 $files = null

Detailed Description

PRONTO WEB FRAMEWORK Copyright (C) 2006, Judd Vinet

Author:
Judd Vinet <jvinet@zeroflux.org>

Description: Base class for all data models. Many of the methods here will be overridden by subclasses.

NOTE: This class is now deprecated in favor of the newer RecordModel and RecordSelector classes. Please use those instead.

Definition at line 15 of file model.php.


Member Function Documentation

Model_Base::__call ( name,
args 
)

TODO: PHP5 only!

Call like so: $this->set_mycolname($id, $value) and: $this->get_mycolname($id)

Definition at line 463 of file model.php.

References $args, and invalidate().

Model_Base::create (  ) 

Return a new/fresh entity. This method is responsible for returning a brand new, un-edited record that will be used to prepopulate form fields in a "Create" form for this data entity.

Returns:
array

Definition at line 234 of file model.php.

Referenced by create_record().

Model_Base::create_record (  ) 

Definition at line 498 of file model.php.

References create().

Model_Base::delete ( id  ) 

Delete a single entity by PK

Parameters:
int $id

Definition at line 407 of file model.php.

References invalidate().

Model_Base::depend ( model  ) 

Load another model as a dependency of this one.

Parameters:
string $model_name

Definition at line 130 of file model.php.

References Factory::model().

Model_Base::enum_schema (  ) 

Definition at line 503 of file model.php.

References list_params().

Model_Base::get ( id  ) 

Return a single record by PK. Normally, you won't want to override this method. Instead, override the get_record() method, which does the actual fetching/assembling of a data record for use by other objects.

Parameters:
int $id
Returns:
array

Definition at line 247 of file model.php.

References get_record().

Referenced by import_plugin(), and Model_Base().

Model_Base::get_all (  ) 

Fetch all records.

Returns:
array

Definition at line 381 of file model.php.

References get_multi().

Model_Base::get_all_by ( column,
value 
)

Fetch all rows by a specified column. If $column and $value are arrays, then "AND" all the values in the WHERE clause.

Parameters:
mixed $column
mixed $value
Returns:
array

Definition at line 363 of file model.php.

References get_multi().

Model_Base::get_bare ( id  ) 

Return a single bare record by PK. Returns a single row from the table, no other data manipulation is performed. Normally the Model::get_record() method is overridden to do additional data work, so this method serves to retain a plain record-getter.

Parameters:
int $id
Returns:
array

Definition at line 300 of file model.php.

Referenced by get_record().

Model_Base::get_by ( column,
value 
)

Fetch a row by a specified column. If $column and $value are arrays, then "AND" all the values in the WHERE clause.

Parameters:
mixed $column
mixed $value
Returns:
array

Definition at line 342 of file model.php.

Model_Base::get_multi ( ids,
ignore_empty = true 
)

Return multiple records by PK, optionally ignoring empty/false records.

Parameters:
array $ids
boolean $ignore_empty Ignore empty records.
Returns:
array

Definition at line 312 of file model.php.

Referenced by get_all(), and get_all_by().

Model_Base::get_or_404 ( id  ) 

Return an entity or throw a 404 page if not found

Parameters:
int $id
Returns:
array

Definition at line 393 of file model.php.

Model_Base::get_record ( id  ) 

Return a full record for this entity, looked up by PK. Normally you will want to override this method to do any additional work on the record before returning it to the caller.

Parameters:
int $id
Returns:
array

Definition at line 286 of file model.php.

References get_bare().

Referenced by get().

Model_Base::get_value ( id,
column 
)

Return a single column from a single entity by PK

Parameters:
int $id
string $column
Returns:
array

Definition at line 329 of file model.php.

& Model_Base::import_plugin ( name  ) 

Import a plugin (aka "page plugin").

Parameters:
string $name Plugin name

Definition at line 142 of file model.php.

References get(), and Factory::plugin().

Model_Base::insert ( data  ) 

Insert a new entity into the table

Parameters:
array $data
Returns:
int The insert ID of the newly-inserted row

Definition at line 419 of file model.php.

References sanitize().

Referenced by save().

Model_Base::invalidate ( id  ) 

Remove an entry from the cache

Parameters:
mixed $id PK of the record to be invalidated from the cache. Use an array if invalidating multiple records.

Definition at line 267 of file model.php.

Referenced by __call(), delete(), and update().

Model_Base::list_params (  ) 

Return some data used for generating smart SQL for lists/grids.

Returns:
array

Definition at line 442 of file model.php.

Referenced by enum_schema().

Model_Base::load ( id  ) 

Definition at line 493 of file model.php.

Model_Base::Model_Base (  ) 

Constructor for all models

Definition at line 104 of file model.php.

References get().

Referenced by Model::Model().

Model_Base::purify ( data  ) 

Use the HTML checker to remove any possible XSS attacks (eg, <script> tags)

Parameters:
array $data
Returns:
array

Definition at line 199 of file model.php.

References DS.

Referenced by sanitize().

Model_Base::sanitize ( data  ) 

Used to do any necessary sanitization on the data before putting it in the DB. addslashes() stuff is not necessary.

Parameters:
array $data
Returns:
array

Definition at line 221 of file model.php.

References purify().

Referenced by insert(), and update().

Model_Base::save ( data  ) 

BACKWARDS COMPATIBILITY

This makes the basic model functions compatible with the newer RecordModel class.

Definition at line 484 of file model.php.

References insert(), and update().

Model_Base::update ( data  ) 

Update an entity

Parameters:
array $data

Definition at line 430 of file model.php.

References invalidate(), and sanitize().

Referenced by save().

Model_Base::validate ( data,
is_update = false 
)

Perform the correct validation routine depending on insert/update mode.

Parameters:
array $data
bool $is_update Whether this data manipulation is an UPDATE or not
Returns:
array Associative array of errors

Definition at line 185 of file model.php.

References validate_for_insert(), and validate_for_update().

Model_Base::validate_for_insert ( data  ) 

Validate data for an INSERT. To be overridden by subclasses.

Parameters:
array $data
Returns:
array Associative array of errors

Definition at line 162 of file model.php.

Referenced by validate().

Model_Base::validate_for_update ( data  ) 

Validate data for an UPDATE. To be overridden by subclasses.

Parameters:
array $data
Returns:
array Associative array of errors

Definition at line 173 of file model.php.

Referenced by validate().


Member Data Documentation

Model_Base::$cache = null

Definition at line 19 of file model.php.

Model_Base::$context = null

This can be set by the page controller acting on the model. It defines the context with which a record is being modified. For example, a Page_CRUD controller may set the model's context to 'ADMIN', indicating that an authorized administrator is modifying a record from a backend admin console, and so regular validation should be bypassed.

The model can then act on this setting in its overridden methods (such as validate, insert, update, etc.)

This setting is optional.

Definition at line 36 of file model.php.

Model_Base::$db = null

Definition at line 17 of file model.php.

Model_Base::$default_sort = 'id'

Default column to sort by

Definition at line 53 of file model.php.

Model_Base::$depends = null

Definition at line 20 of file model.php.

Model_Base::$enable_cache = false

Enable caching for this entity. Only enable this if you plan to be diligent about _only_ inserting/updating/fetching/deleting this entity _through_ the model interface. If you interact with the data yourself (eg, through $this->db in a controller) then you will undermine the caching layer.

Definition at line 65 of file model.php.

Model_Base::$files = null

An array of files associated with this model, used by Page_CRUD to handle file uploads. The 'type' element determines the acceptable MIME type(s). Use an array for multiple types, or "image" to accept normal image types. Omit it to accept any file.

If type==image, then images will be converted to JPEG for consistency. If type==image, then use 'max_width' and 'max_height' to optionally resize images, maintaining aspect ratio.

The filename parameter can include any values from the record returned from the model's get() method. Each data key should be surrounded in angle brackets (eg, "<name>").

Array keys in $files must match those of the create/edit form defined in the template.

Example:

         var $files = array(
           'image' => array(
             'type'       => 'image',
             'max_width'  => '640',      // used for type==image only
             'max_height' => '800',      // used for type==image only
             'webroot'    => DIR_WS_DATA_IMG,
             'fileroot'   => DIR_FS_DATA_IMG,
             'filename'   => "<id>.jpg"
           )
         );

Definition at line 98 of file model.php.

Model_Base::$per_page = 50

Default number of items to show per page

Definition at line 57 of file model.php.

Model_Base::$pk = 'id'

Name of the PK column in this table (one column only)

Definition at line 49 of file model.php.

Model_Base::$plugins = null

Definition at line 21 of file model.php.

Model_Base::$table = null

Name of database table this model will use

Definition at line 45 of file model.php.

Model_Base::$web = null

Definition at line 18 of file model.php.


The documentation for this class was generated from the following file:

Generated on Wed Jan 13 09:21:04 2010 for Pronto Framework by  doxygen 1.6.1