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) »
  • api class causing fatal error when called from joomla hook
Pages: [1]

Author Topic: api class causing fatal error when called from joomla hook  (Read 654 times)

usr238496

  • I post occasionally
  • **
  • Posts: 85
  • Karma: 0
  • CiviCRM version: latest
  • CMS version: joomla2.5
  • PHP version: 5 something
api class causing fatal error when called from joomla hook
June 20, 2012, 07:41:26 am
Good morning, guys.

I am hooking into the Joomla event
Code: [Select]
function onAfterInitialise()
From here I wanted to use the Civicrm api,

however, when I tried to require the api class with
Code: [Select]
require_once 'api/api.php';I got file not found. I am not sure, how the paths are working as the same line does work from a different hook.
Anyway, no problem, I can use the absolute path I thought to the api file

Code: [Select]
$joomlaRootWithEndSlash .'administrator/components/com_civicrm/civicrm/api/api.php'

This does include the file, but now the actual api.php file is trying to load other files, and these are now failing.

error
Code: [Select]
Warning: require_once(api/v3/utils.php) [function.require-once]: failed to open stream: No such file or directory in /home/XXXXX/XXXXX/administrator/components/com_civicrm/civicrm/api/api.php on line 23

Am I not able to use the civicrm api from joomla event hooks?

I have just tested with a civi hook and the code works fine.
You did not answer the verification questions correctly - sigh

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: api class causing fatal error when called from joomla hook
June 20, 2012, 07:52:31 am
try calling civicrm_initialize(); it should be enough.

(you don't need to include api/api.php)
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

usr238496

  • I post occasionally
  • **
  • Posts: 85
  • Karma: 0
  • CiviCRM version: latest
  • CMS version: joomla2.5
  • PHP version: 5 something
Re: api class causing fatal error when called from joomla hook
June 20, 2012, 08:20:12 am
Code: [Select]
Fatal error: Call to undefined function civicrm_initialize()

:(

Doesn't seem to work
You did not answer the verification questions correctly - sigh

usr238496

  • I post occasionally
  • **
  • Posts: 85
  • Karma: 0
  • CiviCRM version: latest
  • CMS version: joomla2.5
  • PHP version: 5 something
Re: api class causing fatal error when called from joomla hook
June 20, 2012, 08:25:38 am
After searching on the function call I found this thread

http://forum.civicrm.org/index.php?topic=20989.0

Seems to be a similar issue, instantiating the Joomla civicrm to be able to fire civihooks before they would be loaded normally.

Hopefully, they work, if not, I shall be back  8)
You did not answer the verification questions correctly - sigh

usr238496

  • I post occasionally
  • **
  • Posts: 85
  • Karma: 0
  • CiviCRM version: latest
  • CMS version: joomla2.5
  • PHP version: 5 something
Re: api class causing fatal error when called from joomla hook
June 20, 2012, 08:32:09 am
As detailed in the other thread mentioned above, the following works, if you are trying to call the api from a  plugin. Am not sure if the singleton code is needed, but I am not touching anything as it works, so that is good enough for me.

Code: [Select]
//get patht to joomla root
$joomlaRootWithEndSlash = substr(__FILE__, 0,strpos(__FILE__, 'plugins'));
//build absolute path to civi settings file
$fpApiCivicrm = $joomlaRootWithEndSlash .'administrator/components/com_civicrm/civicrm.settings.php';
//add file
require_once $fpApiCivicrm;
require_once 'CRM/Core/Config.php';
$config = CRM_Core_Config::singleton( );
You did not answer the verification questions correctly - sigh

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • api class causing fatal error when called from joomla hook

This forum was archived on 2017-11-26.