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 (Moderator: Donald Lobo) »
  • adding a civicrm module
Pages: [1]

Author Topic: adding a civicrm module  (Read 2027 times)

dougall

  • Guest
adding a civicrm module
March 04, 2008, 08:38:12 am
hi,

i'm trying to add a civicrm module so that i can monitor civicrm_post hooks and run some php code accordingly (using Drupal 5.7 and CiviCRM 1.9.13019)

i followed these instructions:
http://wiki.civicrm.org/confluence/display/CRM/Creating+CiviCRM+Modules
and the basic drupal module is working fine.

i've then tried to access the civicrm api in the manner outlined here:
http://wiki.civicrm.org/confluence/display/CRMDOC/Using+CiviCRM+APIs+-+Code+Snippets

....but i'm getting an error message:
Quote
unrecoverable error
 Sorry. A non-recoverable error has occurred.

and the error details are an array which contains several fields, including:
    message => DB Error: no database selected
&
    code => -14


Here's the code for my test module:
Code: [Select]
<?php
/**
 * pxp.module - module for the pxp project
 */

require_once("C:/wamp/www/drupal-5.7/sites/default/civicrm.settings.php");
global 
$civicrm_root;

require_once(
$civicrm_root.'/CRM/Core/Config.php');
require_once(
$civicrm_root.'/api/crm.php');

$config =& CRM_Core_Config::singleton( );

the code is explicit about the path in require_once(...) since, for some strange reason, when using a relative path the civicrm.settings.php file is not found  :-\

..and the code for the corresponding pxp.info
Code: [Select]
name = PxP
description = PxP test module
version = 0.1
dependencies = civicrm
package = CiviCRM

i may well be doing something daft since i'm new to CiviCRM and Drupal.

thanks,
  dougall



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: adding a civicrm module
March 04, 2008, 11:41:09 pm


can u try this instead

Code: [Select]
civicrm_initialize( true );

// make your call here

The function civicrm_initialize( ); is present in civicrm.module and hence drupal should load it on every page request

lobo


A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

dougall

  • Guest
Re: adding a civicrm module
March 05, 2008, 02:13:44 am
thanks, that's just what i needed to know, the fog has cleared ...
i see i was inappropriately trying to use the code given for standalone scripts in a module.
dougall

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • adding a civicrm module

This forum was archived on 2017-11-26.