TaniPHP
[ class tree: TaniPHP ] [ index: TaniPHP ] [ all elements ]

Class: ActiveModel

Source Location: /activemodel.php

Class Overview


ActiveModel class


Author(s):

  • Dumitru Postoronca

Variables

Methods



Class Details

[line 17]
ActiveModel class

ActiveModel class




Tags:

author:  Dumitru Postoronca


[ Top ]


Class Variables

$belongs_to = array()

[line 70]

Array of models this model belongs to

Array of models this model belongs to



Type:   array


[ Top ]

$db =

[line 115]

Database connection

Database connection




Tags:

private:  

Type:   object


[ Top ]

$display_field =  'title'

[line 107]

Field to display when this table is used in a belongs_to association

Field to display when this table is used in a belongs_to association



Type:   string


[ Top ]

$has_and_belongs_to = array()

[line 86]

Array of models with n-m relationships

Array of models with n-m relationships




Tags:


Type:   array


[ Top ]

$has_many = array()

[line 63]

Array of models this model has

Array of models this model has




Tags:

todo:  Cascade delete

Type:   array


[ Top ]

$id =  null

[line 24]

ID field for table

ID field for table



Type:   int


[ Top ]

$one_to_one = array()

[line 78]

Array of models with which we have a one-to-one relationships

Array of models with which we have a one-to-one relationships




Tags:

todo:  Cascade delete

Type:   array


[ Top ]

$table =  null

[line 40]

Table to associate this model with.

Table to associate this model with. If no value is set, the pluralized name of the model will be used



Type:   string


[ Top ]

$upload = array()

[line 100]

Array of fields to treat as file uploads

Array of fields to treat as file uploads Example of creating an image upload field:

  1. var $upload = array('img' => array('maxsize' = 64000, 'type' = array('jpg', 'gif', 'png')));




Tags:

todo:  handle file uploads in insert/update/delete methods

Type:   array


[ Top ]

$validation = array()

[line 55]

Validation rules for different fields

Validation rules for different fields Example:

  1. var $validation = array(
  2. 'name' => array('string', array('format' => VALIDATE_ALPHA, 'minlenth' => 1)),
  3. 'age' => array('number', array('decimal' => '', 'min' => 18, 'max' => 99))
  4. );



Type:   array


[ Top ]

$_fields = array()

[line 32]

Array of table fields

Array of table fields




Tags:

private:  

Type:   array


[ Top ]



Class Methods


constructor ActiveModel [line 124]

ActiveModel ActiveModel( [int $id = 0])

Model constructor

Model constructor Gets the database connection, the associated table name and field types




Parameters:

int   $id   The id of the record to load. If is set to 0(zero) will not load anything.

[ Top ]

method assign [line 181]

void assign( array $values)

Assigns an associative array of values to the model

Assigns an associative array of values to the model




Parameters:

array   $values   Associative array of values to assign

[ Top ]

method delete [line 642]

bool delete( [int $id = null])

Deletes a record from the table.

Deletes a record from the table. Example 1:

  1. $post = new Post;
  2. $post->id = 1;
  3. $post->delete();
Example 2:
  1. $post = new Post;
  2. $post->delete(1);




Tags:

return:  True if SQL executed succesfully


Parameters:

int   $id   ID to be used for deletion

[ Top ]

method find [line 319]

void find( int $id, [mixed $loadRelationships = true], bool $loadRelationship)

Finds a record by id

Finds a record by id




Parameters:

int   $id   Table id
bool   $loadRelationship   True if you want table relationships loaded too

[ Top ]

method findAll [line 496]

array findAll( [mixed $loadRelationships = true], bool $loadRelationship)

Finds all records in a database.

Finds all records in a database. Returns items as array of model objects




Tags:

return:  Array of found objects


Parameters:

bool   $loadRelationship   True if you want table relationships loaded too

[ Top ]

method findRoR [line 359]

void findRoR( )

Finds using RoR-like parameters

Finds using RoR-like parameters Example 1:

  1. $post->findRoR(1);
Example 2:
  1. $post->findRoR(":sql", "SELECT * FROM posts");
Example 3:
  1. echo $post->findRoR(":conditions", "title = 'first'");
Example 4:
  1. echo $post->findRoR("title", "first");
Example 5:
  1. // don't know how/when to use this
  2. echo $post->findRoR(':all', ':join', 'posts');
Example 6: // :limit takes two params echo $post->findRoR(':all', ':limit', 0, 3);




[ Top ]

method insert [line 533]

bool insert( )

Inserts a new record in the database

Inserts a new record in the database




Tags:

return:  True if query was succesfull, false if not


[ Top ]

method loadRelationships [line 220]

void loadRelationships( )

Loads relationships with other tables.

Loads relationships with other tables.




[ Top ]

method update [line 570]

bool update( )

Updates records in the database

Updates records in the database




Tags:

return:  True if query was succesfull, false if not


[ Top ]


Documentation generated on Fri, 16 Dec 2005 13:16:33 +0200 by phpDocumentor 1.3.0RC4