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) »
  • Support »
  • Using CiviCRM »
  • Using Joomla Extensions (Moderator: lcdweb) »
  • API - I must be doing something stupid
Pages: [1]

Author Topic: API - I must be doing something stupid  (Read 3681 times)

trevorwood

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 4
  • CiviCRM version: 4.0.2
  • CMS version: Joomla 1.6
  • MySQL version: 5.0.51a
  • PHP version: 5.2.6-1+lenny8
API - I must be doing something stupid
July 20, 2011, 03:35:53 am
I'm trying to use the CiviCRM API to create some functionality for the front end of a Joomla based website

I'm using Jumi to insert the path to the php file

The PHP file in question is stored in "administrator\components\com_civicrm\civicrm" (at least for the time being - I'll want to move it out to a dedicated code library directory)

The PHP code is simple (at least at the moment)

print ("<h3>Leicester Business Club Members</h3><p>This page will - eventually - list all the members of the specified Business Club</p>");

require_once 'api/api.php';

$params = array(
  'version' => 3,
);

$result = civicrm_api( 'contact','get',$params );

However I'm getting the following error message from api.php

Warning: require_once(api/v3/utils.php) [function.require-once]: failed to open stream: No such file or directory in D:\websites\joomla\administrator\components\com_civicrm\civicrm\api\api.php on line 47

Fatal error: require_once() [function.require]: Failed opening required 'api/v3/utils.php' (include_path='.;c:\php\includes') in D:\websites\joomla\administrator\components\com_civicrm\civicrm\api\api.php on line 47


utils.php is in the api/v3 directory, so what am I doing wrong

Server is Windows XP running Apache. Jumla and CiviCRM are all up to date

As a follow on, what would I need to change to move the file to top a subdirectory (php-library) off the top level of the website - do I only need to change the path to the api.php?

Cheers

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: API - I must be doing something stupid
July 20, 2011, 05:09:53 am
you haven't instantiated civicrm so the include paths aren't registered

at the beginning of your code, try adding this:

Code: [Select]
require_once JPATH_ROOT.'/'.'administrator/components/com_civicrm/civicrm.settings.php';
require_once 'CRM/Core/Config.php';
$civiConfig =& CRM_Core_Config::singleton( );

also -- if you're making a list or searchable member directory, be sure to explore the profile tools in civi. you may be able to do most or all of the required functionality out of the box, without generating custom code.
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

trevorwood

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 4
  • CiviCRM version: 4.0.2
  • CMS version: Joomla 1.6
  • MySQL version: 5.0.51a
  • PHP version: 5.2.6-1+lenny8
Re: API - I must be doing something stupid
July 20, 2011, 06:03:14 am
Thanks I'll try that. Where was that documented?

I've looked at the profile tools, but it seems as though they're only accessible when logged in to the back end of Joomla (although I'll be happy to be shown wrong) and I need to do this at the front end.

trevorwood

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 4
  • CiviCRM version: 4.0.2
  • CMS version: Joomla 1.6
  • MySQL version: 5.0.51a
  • PHP version: 5.2.6-1+lenny8
Re: API - I must be doing something stupid
July 20, 2011, 06:08:00 am
That appears to have fixed it - thanks

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: API - I must be doing something stupid
July 20, 2011, 06:12:04 am
profiles can all be exposed through the front of the site -- in create/edit/view/search modes.
try creating a new joomla menu item for civicrm. you'll see the list of options available for frontend civi pages.
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

trevorwood

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 4
  • CiviCRM version: 4.0.2
  • CMS version: Joomla 1.6
  • MySQL version: 5.0.51a
  • PHP version: 5.2.6-1+lenny8
Re: API - I must be doing something stupid
July 27, 2011, 03:07:29 am
Thanks - unfortunately, they don't quite do what I want

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: API - I must be doing something stupid
July 27, 2011, 05:23:31 am
You can sometimes uses the profile as the basis, and then enhance it with the buildForm hook and postProcess hook, is that an option for you?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

trevorwood

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 4
  • CiviCRM version: 4.0.2
  • CMS version: Joomla 1.6
  • MySQL version: 5.0.51a
  • PHP version: 5.2.6-1+lenny8
Re: API - I must be doing something stupid
July 27, 2011, 08:45:22 am
Don't know - but given my level of PHP hand coding isn't an issue

Actually - following on from this - if I want to do a quick and dirty and query the CiviCRM database directly, is there something already set up to connect & access it or do i have to start from scratch?

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: API - I must be doing something stupid
July 27, 2011, 08:53:29 am
If you want to do it quick and dirty you can use CRM_Core_DAO::executeQuery( $yourQuery )
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

trevorwood

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 4
  • CiviCRM version: 4.0.2
  • CMS version: Joomla 1.6
  • MySQL version: 5.0.51a
  • PHP version: 5.2.6-1+lenny8
Re: API - I must be doing something stupid
July 27, 2011, 09:15:57 am
Wonderful. thanks

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: API - I must be doing something stupid
July 27, 2011, 09:18:45 am
and obviously you will need to do something like this:
Code: [Select]
$qry = "SELECT * FROM civicrm_contact";
$daoContact = CRM_Core_DAO::executeQuery( $qry );
while ($daoContact->fetch()) {
<do your processing>
}

Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

jstn

  • I’m new here
  • *
  • Posts: 10
  • Karma: 0
  • CiviCRM version: 4.0.0
  • CMS version: Drupal 7 Stable
  • MySQL version: Recent Stable?
  • PHP version: PHP 5
Re: API - I must be doing something stupid
January 05, 2012, 06:12:11 am
I am having the same issue with a Drupal 7 installation. I don't see a path for require_once '/administrator/components/com_civicrm/civicrm.settings.php'. What needs to be done to fix this issue in a Drupal installation?

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: API - I must be doing something stupid
January 05, 2012, 06:32:38 am
I am not sure I fully understand your question....your civicrm.setting.php should be in <yoursite>/sites/default
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: API - I must be doing something stupid
January 06, 2012, 04:22:20 am
Quote from: jstn on January 05, 2012, 06:12:11 am
I am having the same issue with a Drupal 7 installation. I don't see a path for require_once '/administrator/components/com_civicrm/civicrm.settings.php'. What needs to be done to fix this issue in a Drupal installation?

In Drupal you should be using custom code in a module, or maybe even on a page or block. Either way, you don't need to include that file, as it's included for you. Just be sure to run

Code: [Select]
  civicrm_initialize();
Before you use any API code. That's all you need.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Joomla Extensions (Moderator: lcdweb) »
  • API - I must be doing something stupid

This forum was archived on 2017-11-26.