Getting and Storing Data for a Custom Data Type
Once you have registered and defined your custom object type. You can easily save instances of the object, or retrieve and/or delete them from the database. Here are some very simple code samples which cover the basics of retrieving and storing these custom objects from the database:
Inserting Data
my $object = TestPlugin::SuperHappyVideo->new;
$object->blog_id(1);
$object->title("My latest video");
$object->length(120);
$object->description("The best video in the world.");
$object->save;
Loading and Updating Data
my $object = TestPlugin::SuperHappyVideo->load({ id => 4 });
$object->title("My latest HAPPY video!");
$object->save;
Deleting Data
my $object = TestPlugin::SuperHappyVideo->load({ id => 4 });
$object->remove;
There are a number of different functions Movable Type makes available to you to make it easier to query and manipulate data in the database. Some of these functions are:
loadload_iterget_by_keyremoveremove_allremove_childrensaveset_by_keyinitjoinuniquecountcount_group_byexists
For complete documentation on creating custom objects, please consult Appendix B.
- Previous: Extending Existing Objects
- Next: Interfaces

Leave a note
Have a question, please use the MT Forums. Notes sumbitted here should pertain to tips & hints regarding documentation. Your note may be removed once it's contents has be integrated into the body of the page.