Add data to mysql on install addon

Permalink
Hello,
I'm trying to create one add-on for C5. I have the controller with the install() method and the db.xml with the necessary tables.

My problem is I want to insert some data to my tables when I'm installing the extension. How to achieve it?

Should I add the Insert queries inside install() method? Can I add the data in db.xml? What is the best approach?

Thanks!

 
formigo replied on at Permalink Best Answer Reply
formigo
I would generally do this in the controller's install method - something like the below example which uses a model:-

package/controller.php
$pkg = parent::install();
loader::model('myModelFile', $pkg);
$insert = myModel::insertData();


/models/myModelFile.php
class myModel {
  public static function insertData() {
    $db=loader::db();
    $sql ="insert into etc...";
    return $db->execute($sql);
  }
}


Hope that's useful
jacking replied on at Permalink Reply
That's it! Perfect!
Thanks ;)