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) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • including the file "civicrm.config.php"
Pages: [1]

Author Topic: including the file "civicrm.config.php"  (Read 883 times)

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
including the file "civicrm.config.php"
September 04, 2010, 05:36:39 am
I have written some custom batch programs that utilize the APIs.  The issue I have is that to include the path to the file civicrm.config.php depends on the CMS structure.
 My current code is:
------------------------------------
        // Joomla path
   // require_once '../../administrator/components/com_civicrm/civicrm/civicrm.config.php';
       
   // Drupal path
   require_once '../../sites/all/modules/civicrm/civicrm.config.php';
------------------------------------

Then I adjust which is commented out depending on the CMS in use.   Any ideas on how I can make this "require_once" truly generic?

Thanks,
Sarah
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: including the file "civicrm.config.php"
September 04, 2010, 04:32:05 pm

i had the same issue between a development and production site. i think this will work for me. snippet of my code file

Code: [Select]
global $civicrm_root;
if ( file_exists( '/Users/lobo/svn/crm_32/' ) ) {
    $civicrm_root = '/Users/lobo/svn/crm_32/';
} else if ( file_exists( '/var/www/sfschool.civicrm.org/public/sites/sfschool.civicrm.org/modules/civicrm/' ) ) {
    $civicrm_root = '/var/www/sfschool.civicrm.org/public/sites/sfschool.civicrm.org/modules/civicrm/';
} else if ( file_exists( '/home/sfschool/www/drupal/sites/all/modules/civicrm/' ) ) {
    $civicrm_root = '/home/sfschool/www/drupal/sites/all/modules/civicrm/';
}

function sfs_bin_Utils_auth( ) {
    session_start( );

    global $civicrm_root;

    require_once "$civicrm_root/civicrm.config.php";
    require_once 'CRM/Core/Config.php';

    $config =& CRM_Core_Config::singleton();
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • including the file "civicrm.config.php"

This forum was archived on 2017-11-26.