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?

3 Answers 3

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

5
  • 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. Commented Aug 7, 2015 at 2:51
  • Detailed steps for this process are now documented here: docs.civicrm.org/dev/en/latest/extensions/civix/…
    – Sean
    Commented Apr 26, 2017 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 Commented Jul 1, 2017 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 Commented Jul 1, 2017 at 16:20
  • @ManiMuthuPandi, start a new question ;)
    – Xavier
    Commented Jul 3, 2017 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 and acknowledge you have read our privacy policy.

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