Created
December 3, 2010 03:58
-
-
Save dhrrgn/726563 to your computer and use it in GitHub Desktop.
An Example ActiveRecord model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
} | |
} |
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
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