CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • Bootstrapping CiviCRM and talking to extensions
Pages: [1]

Author Topic: Bootstrapping CiviCRM and talking to extensions  (Read 1445 times)

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Bootstrapping CiviCRM and talking to extensions
September 15, 2011, 06:15:22 pm
Related to current discussion (other thread) about IPN callbacks, in the meantime I want to fire up CiviCRM and start using some methods implemented in extension classes.

I noticed that the Ogone processor IPN references CRM_Core_Payment_OgoneIPN::main without even having to include the class file. "Great!", I thought, "CiviCRM must automatically load the core file from each extension. Easy!". Nope.

So I did this instead:

Code: [Select]
session_start( );
require_once '../civicrm.config.php';
require_once 'CRM/Core/Config.php';
$config = CRM_Core_Config::singleton();

// Probably there's a cleaner way to require an extension's base file?
require_once 'CRM/Core/Extensions/Extension.php';
$ext = new CRM_Core_Extensions_Extension( 'nz.co.giantrobot.flo2cashdonate' );
if ( !empty( $ext->path ) ) {
    require_once $ext->path . '/Flo2CashDonate.php';
}
https://github.com/GiantRobot/civicrm_flo2cash_donate/blob/master/nz.co.giantrobot.flo2cashdonate/f2c_ipn.php#L9

Is there an easier, cleaner way to achieve this? If there was then f2c_ipn.php would more like ten lines than thirty.
@xurizaemon ● www.fuzion.co.nz

Michał Mach

  • Ask me questions
  • ****
  • Posts: 748
  • Karma: 59
    • CiviCRM site
  • CiviCRM version: latest
  • CMS version: Drupal and Joomla latest
  • MySQL version: numerous
  • PHP version: 5.3 and 5.2
Re: Bootstrapping CiviCRM and talking to extensions
September 16, 2011, 07:08:35 am
My first impression is that that's the best way, nothing cleaner comes to mind - you're in "external script" which doesn't know where the actual extensions is at the moment.

Thx,
m
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

My absolute favourite: Wordpress Integration!.

Donate Now!

zorgalina

  • I post occasionally
  • **
  • Posts: 34
  • Karma: 0
  • CiviCRM version: 4.3.5
  • CMS version: Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Bootstrapping CiviCRM and talking to extensions
November 26, 2013, 10:57:26 am
This is something I wanted to ask about - how to include extension classes/code in a new custom report (or any custom code).  I hope this will be added to Extension documentation - or is there a 'wiki' that can be a repository for information to get folded into official CiviCRM documentation?

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Re: Bootstrapping CiviCRM and talking to extensions
November 26, 2013, 11:55:33 am
Not sure what you're hoping to achieve exactly but check these out -

* https://github.com/totten/civix/ - civix tool for generating extensions (incl custom report extensions)
* http://wiki.civicrm.org/confluence/plugins/servlet/mobile#content/view/86213555 - create an extension docs in wiki

Since civix extensions can provide reports, that may well cover your needs. If you're asking about ways to detect and refer to code in extension A from extension B, I don't know of tools for doing that in civicrm (equivalents in Drupal would be things like module_exists() and drupal_get_path()).

HTH
@xurizaemon ● www.fuzion.co.nz

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • Bootstrapping CiviCRM and talking to extensions

This forum was archived on 2017-11-26.