Ejemplo n.º 1
0
function render($view_name = '', $layout = 'default', $extra_vars = null)
{
    if ('' == $view_name || null == $view_name) {
        # TODO: Determine the default view to use for the controller we were called from.
    }
    # Find the view file. Return silently if not found.
    $view_file = php_file($view_name, VIEWS_DIR);
    if (null == $view_file) {
        return;
    }
    # Find the layout file.
    $layout_file = php_file($layout, LAYOUTS_DIR);
    # Render the view_file, with or without the layout.
    if (null == $layout_file) {
        render_file_with_no_layout($view_file, $extra_vars);
    } else {
        render_file_with_layout($view_file, $layout_file, $extra_vars);
    }
}
Ejemplo n.º 2
0
<?php

require_once php_file('database', CONFIG_DIR);
## TODO: Handle data types and proper quoting of strings (but not numeric fields).
## TODO: Use PDO instead of MySQL calls. (Perhaps keep MySQL calls for old PHP 4 sites.)
## TODO: Use variable binding, instead of plugging data fields directly into SQL statement.
## TODO: Error handling.
## TODO: load_row and find_rows should probably have similar names.
## TODO: Change names of plural versions to *_where?
## TODO: Change names to SELECT, since we already have INSERT/UPDATE/DELETE.
## TODO: Add a more generic SELECTs, allowing joins, limits, ORDER BY, etc.
## TODO: Add a "raw" SELECT, allowing the SQL to be manually specified. Can use AS, SQL functions, etc.
## NOTE: This is primarily a generic Table Data Gateway implementation.
class DBTable
{
    # Name of the table.
    protected $name;
    # Connection to the database.
    protected $conn;
    # Info about each column.
    protected $column_info = array();
    public function __construct($name)
    {
        $this->name = $name;
        $this->connect();
        $this->get_column_info();
    }
    public function __destruct()
    {
        if ($this->conn) {
            mysql_close($this->conn);
Ejemplo n.º 3
0
<?php

require_once php_file('database', FRAMEWORK_DIR);
## TODO: Determine table name from class name.
## TODO: Use info on columns during loads/saves.
## TODO: Allow sub-classes to define custom properties that aren't in the database (and not stored in $properties).
##			Have getter/setter methods accessible via the array syntax.
##			Have a generic getter/setter that uses the properties array.s
## TODO: Test save() with an object with no ID (i.e. a newly created object, not loaded from the database).
## TODO: Test delete(). What do we do after deletion.
## TODO: Provide some assistance for associations.
## TODO: Find functions.
abstract class BaseModel implements ArrayAccess
{
    # ID of object in database. NOTE: Most likely duplicated in $this->properties['id'].
    protected $id = NULL;
    # Data fields from the database.
    protected $properties;
    # Database table to get items from.
    protected $table_name = NULL;
    protected $table = NULL;
    # Errors from validations
    protected $errors = array();
    public function __construct($id = NULL)
    {
        # TODO: Find default table name from name of the class, pluralized and lower-cased.
        if (NULL == $this->table_name) {
            $this->table_name = NULL;
        }
        # Instantiate a table object.
        $this->table = new DBTable($this->table_name);
Ejemplo n.º 4
0
function __autoload($class)
{
    $file = php_file($class, MODELS_DIR);
    # TODO: See if php_file returned NULL. Perhaps look in other directories.
    require_once $file;
}