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');

    $record2 = new MyPlugin_ExampleRecord;
    $record2->setAttribute('attributeName', 'value2');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.