Skip to content
Permalink
master
Go to file
 
 
Cannot retrieve contributors at this time
95 lines (78 sloc) 1.79 KB

ActiveRecord

Build Status Code Coverage Scrutinizer Code Quality SensioLabsInsight

The Active Record Component.

Example

<?php

use miBadger\ActiveRecord\AbstractActiveRecord;

/**
 * The user class.
 */
class User extends AbstractActiveRecord
{
	/** @var string The name. */
	private $name;

	/**
	 * {@inheritdoc}
	 */
	public function getActiveRecordTable()
	{
		return 'example';
	}

	/**
	 * {@inheritdoc}
	 */
	public function getActiveRecordColumns()
	{
		return [
			'name' => &$name
		];
	}

	/**
	 * Returns the name.
	 *
	 * @return string the name.
	 */
	public function getName()
	{
		return $this->name;
	}

	/**
	 * Sets the name.
	 *
	 * @param string $name
	 * @return $this
	 */
	public function setName($name)
	{
		$this->name = $name;

		return $this;
	}
}
<?php

/**
 * Create an active record instance.
 */
$user = new User($pdo);

/**
 * Read the row with the given ID from the database.
 */
$user->read($id);

/**
 * Returns the name.
 */
$user->getName(); // John

/**
 * Set a new name.
 */
$user->setName('Jane');

/**
 * Synchronize the active record with the database.
 */
$user->sync();
You can’t perform that action at this time.