When I install the plugin, I need to automatically create a few records. How can I have my plugin automatically create those records when it is installed?
On the main MyPluginPlugin
class, there is a method you can override called onAfterInstall()
. Which will run after your plugin is installed.
To create those records, you can place the following code into the method:
public function onAfterInstall()
{
$record = new MyPlugin_ExampleRecord;
$record->setAttribute('attributeName', 'value');
$record->save();
$record2 = new MyPlugin_ExampleRecord;
$record2->setAttribute('attributeName', 'value2');
$record2->save();
}