Skip to content

wearethefoos/CodeIgniter_Gasoline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

#CodeIgniter Gasoline Package# CakePHP-like Model, Behaviors, and Validation

This package provides you with an Application Model that you can extend to make use of its callbacks and built-in validation. The model uses MongoDB as a data source.

###Configuration###

Add this to /config/autoload.php to load the Application Model automatically.

$autoload['model'] = array('application_model');

Update /config/mongo_db.php and set the

$config['mongo_db'] = "your_database_name";

###Model Example###

class Post extends Application_Model {
/**
 * Name of the mongo collection this
 * model uses.
 */
	protected $collection = 'posts';

/**
 * Validation criteria
 */
	public $validate = array(
		'title' => array('required'),
		'body'  => array('required')
	);

/**
 * Behaviors and their settings.
 */	
	public $actsAs = array(
		'Sluggable' => array(
			'field' => 'title',
			'replacement' => '-',
		)
	);

/**
 * Before inserting stuff
 */
	function beforeInsert($data) {
		$this->data['created'] = time();
		parent::beforeInsert($data);
	}

/**
 * Before updating stuff
 */	
	function beforeUpdate($data = array(), $options = array()) {
		$this->data['updated'] = time();
		parent::beforeUpdate($data, $options);
	}
}

Releases

No releases published

Packages

No packages published

Languages