Insert record into DB table while installing an add-on
Permalink 1 user found helpful
Hi
Sometimes it is required to insert some default record into database tables while installing an add-on. I was wondering whether it is possible or not. If possible, then could someone please tell me the code.
Thanks
Sometimes it is required to insert some default record into database tables while installing an add-on. I was wondering whether it is possible or not. If possible, then could someone please tell me the code.
Thanks
If you mean by db.xml file, you can try adding this node into the xml file:
Thanks for this.. I'll have it a try, but is there any way to do that through controller.
Because if there is a lots of pre defined records that I need to insert, then I can easily create an array & pass it to save method so that it can easily inserted.
Rony
Because if there is a lots of pre defined records that I need to insert, then I can easily create an array & pass it to save method so that it can easily inserted.
Rony
That db.xml trick looks useful. I didn't know about that.
In a package controller, the package database tables are created by the parent::install() part. So any time after that you can use the database, or make calls to a model that interfaces to the database.
Block tables are created when the block install calls are made.
One of the tricky parts is to cope with failed installations or partially failed installations, so that the code can adapt to any partially installed data left over by a preceding failed initialisation or incomplete uninstall.
The details really depend on the nature of the tables.
In a package controller, the package database tables are created by the parent::install() part. So any time after that you can use the database, or make calls to a model that interfaces to the database.
Block tables are created when the block install calls are made.
One of the tricky parts is to cope with failed installations or partially failed installations, so that the code can adapt to any partially installed data left over by a preceding failed initialisation or incomplete uninstall.
The details really depend on the nature of the tables.
Inserting rows into the tables at the package main controller manually should not be a problem, you just prepare sql queries and execute them.
http://www.concrete5.org/documentation/introduction/database-access...
http://www.concrete5.org/documentation/introduction/database-access...
Thanks for your suggestion. I hope the controller coding is better than using xml.