Models - fearricepudding/uranium-framework GitHub Wiki

Models documentation

Models represent tables in the database.

Basic model example:

<?php
namespace uranium\model;

use uranium\core\model;
use uranium\core\databaseDataTypes;

class exampleModel extends model{

	protected $tableName = "exampleModel";

	public function __construct(){
		$this->addPrimary("id"); // Defind out primary key

                // Define some data we want in our table
		$this->addCol("name", [
			"type" 	 => databaseDataTypes::VARCHAR,
			"length" => 50,
			"null" => false
		]);

                // Define some other data
		$this->addCol("test", [
			"type" => databaseDataTypes::VARCHAR,
			"null" => false,
			"default" => "Something"
		]);
	}	
}

We can now use this model to select from

$test = new exampleModel();

$test->where("name", "someone")
     ->where("test", "example")
     ->limit(1)
     ->get();