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) »
  • using userID within a hook
Pages: [1]

Author Topic: using userID within a hook  (Read 1079 times)

dflorence

  • I’m new here
  • *
  • Posts: 24
  • Karma: 0
  • CiviCRM version: 4.4.3
  • CMS version: joomla 2.5 and testing 3.2.1
  • MySQL version: 5.1.69
  • PHP version: 5.3.3
using userID within a hook
October 19, 2012, 02:30:58 pm
I want to write my first civicrm_post hook. This needs to add newly created contacts to particular groups depending on the group membership of the user currently logged in. 

 have created a Joomla (2.5)  plugin. with CIVI 4.1 t do this.

I've got the code working to the extent that the newly created contact is ALWAYS added to a particular group, I just need to work out how to get the userID of the current user so I can extend the code to only allocate the newly created contact to a group if the logged in user is of a particular type.

I have tried 
Code: [Select]
$userID  = $session->get( 'userID' );  but get the error "Fatal error: Call to a member function get() on a non-object"

I have also tried using
Code: [Select]
$userID=$_SESSION['userID'], which returns nothing at at all.

I have tried using Session_start() just in case the session variables are not there - still nothing.

I get the feeling I'm missing something simple, this is my first civi install, so pointers that don't take anything for granted would be appreciated  ;)


totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: using userID within a hook
October 19, 2012, 03:08:39 pm
Quote from: dflorence on October 19, 2012, 02:30:58 pm
I have tried 
Code: [Select]
$userID  = $session->get( 'userID' );  but get the error "Fatal error: Call to a member function get() on a non-object"

Have you made a call to lookup $session first?

Code: [Select]
$session = CRM_Core_Session::singleton();
$contactID = $session->get('userID');

dflorence

  • I’m new here
  • *
  • Posts: 24
  • Karma: 0
  • CiviCRM version: 4.4.3
  • CMS version: joomla 2.5 and testing 3.2.1
  • MySQL version: 5.1.69
  • PHP version: 5.3.3
Re: using userID within a hook
October 19, 2012, 03:19:06 pm
Thanks, I didn't know I needed to do that.

Works fine now.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • using userID within a hook

This forum was archived on 2017-11-26.