Skip to content

Instantly share code, notes, and snippets.

@dhrrgn
Created December 3, 2010 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dhrrgn/726563 to your computer and use it in GitHub Desktop.
Save dhrrgn/726563 to your computer and use it in GitHub Desktop.
An Example ActiveRecord model
<?php
// Need to add 'activerecord' to your packages in config.php
namespace Fuel\Application;
use ActiveRecord;
class Model_User extends ActiveRecord\Model {
// This will eventually be "guessed"
protected static $table_name = 'users';
protected $columns = array('id', 'name');
}
<?php
/**
* Example Usage of the ActiveRecord Model.
* Associations do not currently work
*/
namespace Fuel\Application;
class Controller_Welcome extends Controller\Base {
public function action_index()
{
$user = Model_User::find(2);
echo $user->name;
$user->name = 'Jacob';
$user->save();
$user = new Model_User();
$user->name = 'Joe Smith';
$user->save();
}
}
@yorickpeterse
Copy link

Storing columns in the model really shouldn't be needed and can easily be guessed using a DESCRIBE query :) https://github.com/YorickPeterse/Awesome-Record/blob/develop/libraries/Awesome_record.php#L241

@dhrrgn
Copy link
Author

dhrrgn commented Dec 3, 2010

That is just temporary. It will go away soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment