9

I have added tables to my database by writing SQL commands in a sql folder as specified in the given link. Add a database upgrader / Installer / uninstaller.

What I am exactly looking for is a method to access these tables, do I need to write direct SQL for adding records to the table or I should create corresponding DAO and BAO to access the table.

How to create DAO and BAO for a given table in an extension?

5

What I did for the sepa extension is a bit of a hack, but worked ok:

write the xml schema files, as you have them on the (development version) core and run xml/phpGencode.php to generate the dao, that you then copy into the extension folders and voila, you got the tables ready to use (for a few more lines, you got the api files, worthwhile IMO)

The process is now detailed in our developer book

  • This means BAO is still need to be written manually. I found a standard guideline, which needs to be followed, but I am assuming this needs to be done manually. – Siddharth Gupta Aug 7 '15 at 2:51
  • Detailed steps for this process are now documented here: docs.civicrm.org/dev/en/latest/extensions/civix/… – Sean Colsen Apr 26 '17 at 4:14
  • What is development version; I have installed civicrm in my pc with Drupal but could not see the XML folder in civicrm root directory – ManiMuthuPandi Jul 1 '17 at 15:56
  • @Xavier: how to get the development version; In my pc I installed civicrm with drupla 7; No XML folder or xml/phpGencode.php – ManiMuthuPandi Jul 1 '17 at 16:20
  • @ManiMuthuPandi, start a new question ;) – Xavier Jul 3 '17 at 7:17
2

What you're looking for is civix generate:entity. It's marked as "EXPERIMENTAL AND INCOMPLETE" on my copy of civix - though my version might be old. Either way, it should point you in the right direction.

UPDATE: While you should still run civix generate:entity, at the time of this writing, it will create a BAO but NOT a DAO file for you. Use Xavier's technique (the accepted answer).

1

Alternatively, I tend to create the file in sql and then create a DAO in my extension with the few functions that are required. Check https://github.com/CiviCooP/no.maf.oppgavexml/blob/master/CRM/Oppgavexml/DAO/Oppgave.php for an example of a DAO I have copied and pasted into my extension for a table I created in the Upgrade class using

$this->executeSqlFile('sql/create_civicrm_oppgave.sql');

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.