Model
The basis for the Models system.
Summary
| Model | The basis for the Models system. |
| Variables | |
| $caches | Caches every loaded module into a clone of the object. |
| $belongs_to | An array of models that this Model belongs to. This model should have a [modelname]_id column. |
| $has_many | An array of models that belong to this Model. They should have a [thismodel]_id column. |
| $has_one | An array of models that this model has only one of. The models should have a [thismodel]_id column. |
| Functions | |
| __get | Automatically handle model relationships when grabbing attributes of an object. |
| __getPlaceholders | Calls __get with the requested $name, but grabs everything as placeholders. |
| grab | Grabs a single model from the database. |
| search | Returns an array of model objects that are found by the $options array. |
| delete | Deletes a given object. Calls the delete_(model) trigger with the objects ID. |
| deletable | Checks if the User can delete the post. |
| editable | Checks if the User can edit the post. |
| edit_link | Outputs an edit link for the model, if the visitor’s Group.can edit_[model]. |
| delete_link | Outputs a delete link for the post, if the <User.can> delete_[model]. |
__getPlaceholders
| public function __getPlaceholders( | $name | ) |
Calls __get with the requested $name, but grabs everything as placeholders.
Parameters
| $name | Name to call Model.__get with. |
Returns
mixed
See Also
grab
| protected static function grab( | $model, | |||
| $id, | ||||
| $options | = | array() | ) |
Grabs a single model from the database.
Parameters
| $model | The instantiated model class to pass the object to (e.g. Post). |
| $id | The ID of the model to grab. Can be null. |
| $options | An array of options, mostly SQL things. |
Options
| select | What to grab from the table. (modelname)s by default. |
| from | Which table(s) to grab from? (modelname)s.* by default. |
| left_join | A LEFT JOIN associative array. Example: array(“table” => “foo”, “where” => “foo = :bar”) |
| where | A string or array of conditions. array(“__(modelname)s.id = :id”) by default. |
| params | An array of parameters to pass to PDO. array(“:id” => $id) by default. |
| group | A string or array of “GROUP BY” conditions. |
| order | What to order the SQL result by. __(modelname)s.id DESC by default. |
| offset | Offset for SQL query. |
| read_from | An array to read from instead of performing another query. |
search
| protected static function search( | $model, | |||
| $options | = | array(), | ||
| $options_for_object | = | array() | ) |
Returns an array of model objects that are found by the $options array.
Parameters
| $options | An array of options, mostly SQL things. |
| $options_for_object | An array of options for the instantiation of the model. |
Options
| select | What to grab from the table. (modelname)s by default. |
| from | Which table(s) to grab from? (modelname)s.* by default. |
| left_join | A LEFT JOIN associative array. Example: array(“table” => “foo”, “where” => “foo = :bar”) |
| where | A string or array of conditions. array(“__(modelname)s.id = :id”) by default. |
| params | An array of parameters to pass to PDO. array(“:id” => $id) by default. |
| group | A string or array of “GROUP BY” conditions. |
| order | What to order the SQL result by. __(modelname)s.id DESC by default. |
| offset | Offset for SQL query. |
| limit | Limit for SQL query. |
See Also
deletable
| public function deletable( | $user | = | null | ) |
Checks if the User can delete the post.
editable
| public function editable( | $user | = | null | ) |
Checks if the User can edit the post.
edit_link
| public function edit_link( | $text | = | null, | |
| $before | = | null, | ||
| $after | = | null, | ||
| $classes | = | "" | ) |
Outputs an edit link for the model, if the visitor’s Group.can edit_[model].
Parameters
| $text | The text to show for the link. |
| $before | If the link can be shown, show this before it. |
| $after | If the link can be shown, show this after it. |
| $classes | Extra CSS classes for the link, space-delimited. |
delete_link
| public function delete_link( | $text | = | null, | |
| $before | = | null, | ||
| $after | = | null, | ||
| $classes | = | "" | ) |
Outputs a delete link for the post, if the <User.can> delete_[model].
Parameters
| $text | The text to show for the link. |
| $before | If the link can be shown, show this before it. |
| $after | If the link can be shown, show this after it. |
| $classes | Extra CSS classes for the link, space-delimited. |