home
#Install
1. Download PHP ActiveRecord 1.0 from [http://www.phpactiverecord.org/download](http://www.phpactiverecord.org/download)
2. Clone li3_activerecord plugin
{{{
cd /path/to/your/app/libraries
git clone code@rad-dev.org:li3_activerecord.git
}}}
3. Add li3_activerecord plugin
Then edit app/config/bootstrap/libraries.php and add the following:
{{{
 Libraries::add('li3_activerecord');
}}}
4. Setup your connection
{{{
Connections::add('default', array(
	'type' => 'ActiveRecord',
	'driver' => 'MySql',
	'host' => '127.0.0.1',
	'login' => 'root',
	'password' => '',
	'database' => 'project'
));
Connections::get('default'); // do not delete this line!
}}}
5. Your models must extend ```\li3_activerecord\extensions\data\Model```
{{{
<?php
    namespace app\models;
    class User extends \li3_activerecord\extensions\data\Model {
    }
?>
}}}
6. Open ```/lithihum/template/helper/Form.php``` and find ```create``` method. Change:
{{{
public function create(\lithium\data\Entity $binding = null, array $options = array()) {
}}}
to
{{{
public function create($binding = null, array $options = array()) {
}}}

#Relations
You can find full description at [http://www.phpactiverecord.org/projects/main/wiki/Associations](http://www.phpactiverecord.org/projects/main/wiki/Associations)
There is only one change. You have to always specify ```class_name```:
{{{
static $has_many = array(
    array('comments', 'class_name' =>'\app\models\Comment')
);
}}}
#Controller example
Here is a simple controller example with ```add``` and ```edit``` actions.
{{{
<?php

namespace app\controllers;

use \app\models\User;

class UsersController extends \lithium\action\Controller {

	public function index() {
		$users = User::all();
		return compact('users');
	}

	public function view($id = null) {
		$user = User::find($this->request->id);
		return compact('user');
	}

	public function add() {
		if (!empty($this->request->data)) {
			$user = User::create($this->request->data);
			if ($user->save()) {
				$this->redirect(array(
					'controller' => 'users', 'action' => 'view',
					'args' => array($user->id)
				));
			}
		}
		if (empty($user)) {
			$user = new User;
		}
		return compact('user');
	}

	public function edit() {
		if (empty($this->request->data)) {
			$user = User::find($this->request->id);
			if (empty($user)) {
				$this->redirect(array('controller' => 'users', 'action' => 'index'));
			}
		} else {
			$user = User::find($this->request->data['id']);
			if ($user->update_attributes($this->request->data)) {
				$this->redirect(array(
					'controller' => 'users', 'action' => 'view',
					'args' => array($user->id)
				));
			}
		}
		return compact('user');
		
	}
}

?>
}}}