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) »
  • How to Initiate CiviCRM Session
Pages: [1]

Author Topic: How to Initiate CiviCRM Session  (Read 1021 times)

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
How to Initiate CiviCRM Session
May 11, 2011, 07:47:32 am
On a Drupal 6 CiviCRM 3.3.6 site, I have a custom module which logs in a user under certain circumstances. His landing page is civicrm but the CiviCRM menu is empty.

The reason is that in CRM/Core/Smarty.php we have this code:
 
Code: [Select]
       if ( !CRM_Core_Config::isUpgradeMode() && $buildNavigation ) {
            require_once 'CRM/Core/BAO/Navigation.php';
            $contactID = $session->get('userID');
            if ( $contactID ) {
                $navigation =& CRM_Core_BAO_Navigation::createNavigation( $contactID );
                $this->assign('navigation', $navigation );
            }
        }

but $session->get('userID') returns nothing so no navigation is built. Here is my code:

Code: [Select]
      global $user;
      $user = user_load(array('uid' => $uid));
      civicrm_initialize(TRUE);
      session_start( ); 

and I have tried several variations, but nothing seems to work.

Any ideas?
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.

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: How to Initiate CiviCRM Session
May 11, 2011, 01:36:53 pm

in your custom login, r u invoking the drupal hook_user

civicrm traps that and does a few thing during login (i.e. sets the session userID)

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

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: How to Initiate CiviCRM Session
May 12, 2011, 05:33:13 am
Fantastic. That did it:

Code: [Select]
      module_invoke('civicrm','user','login',$edit,$user);
Thank you.
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) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • How to Initiate CiviCRM Session

This forum was archived on 2017-11-26.