Skip to Content Skip to Menu

🎃 Happy Halloween! Treat yourself with an awesome discount on memberships! Get 20% off now with code SPOOKY-2024!

[SOLVED] Trying to get a CB user object, but that exhausts memory?

  • fribse2011
  • fribse2011
  • OFFLINE
  • Posts: 921
  • Thanks: 79
  • Karma: 8
8 years 6 months ago - 8 years 5 months ago #280968 by fribse2011
Hi All

I'm trying to prepopulate a form with user data, but using this code exchausts the memory, what am I doing wrong?
Code:
<?php global $_CB_framework, $mainframe; if ( defined( 'JPATH_ADMINISTRATOR' ) ) { if ( ! file_exists( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' ) ) { echo 'CB not installed!'; return; } include_once( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' ); } else { if ( ! file_exists( $mainframe->getCfg( 'absolute_path' ) . '/administrator/components/com_comprofiler/plugin.foundation.php' ) ) { echo 'CB not installed!'; return; } include_once( $mainframe->getCfg( 'absolute_path' ) . '/administrator/components/com_comprofiler/plugin.foundation.php' ); } $user =& CBuser::getUserDataInstance( $_CB_framework->myId() ); $form->data['navn1'] = $user->name; $form->data['email1'] = $user->email; $form->data['mobil1'] = $user->cb_cell; $form->data['adresse1'] =& $user->cb_adresse; $form->data['post1'] = $user->cb_postnummer; ?>

This is J3.5.1 and CB 2.0.14

Best regards
Fribse

Frømandsklubben Nikon, www.nikondyk.dk
We're a volunteer driven diving club in Ishøj, Denmark.
Har du brug for en dykkerklub der rummer alle, så kom ned til os.
Last edit: 8 years 5 months ago by krileon.

Please Log in or Create an account to join the conversation.

  • fribse2011
  • fribse2011
  • OFFLINE
  • Posts: 921
  • Thanks: 79
  • Karma: 8
8 years 6 months ago #280992 by fribse2011
Ok, I found another tutorial that seems to do the trick, so now the code looks like this:
Code:
<?php Global $_CB_framework ; $myId = $_CB_framework->myId() ; $cbUser =& CBuser::getInstance( $myId ) ; if ( ! $cbUser ) { $cbUser =& CBuser::getInstance( null ) ; } $user =& $cbUser->getUserData() ; $form->data['navn1'] = $user->name ; $form->data['email1'] = $user->email ; $form->data['mobil1'] = $user->cb_cell ; $form->data['adresse1'] =& $user->cb_adresse ; $form->data['post1'] = $user->cb_postnummer ; ?>

Best regards
Fribse

Frømandsklubben Nikon, www.nikondyk.dk
We're a volunteer driven diving club in Ishøj, Denmark.
Har du brug for en dykkerklub der rummer alle, så kom ned til os.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48460
  • Thanks: 8280
  • Karma: 1443
8 years 6 months ago - 8 years 6 months ago #281009 by krileon
First usage has out dated API loader. You'll need to use the below to load in CB.

Code:
if ( ( ! file_exists( JPATH_SITE . '/libraries/CBLib/CBLib/Core/CBLib.php' ) ) || ( ! file_exists( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' ) ) ) { return; } include_once( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' );

Next you need to load in some API to use. To reliably do this I recommend just calling the below.
Code:
cbimport( 'cb.html' );

Next for the viewing user object you'd call the below.

Code:
$cbUser = CBuser::getMyUserDataInstance();

All together it'd be as follows.

Code:
if ( ( ! file_exists( JPATH_SITE . '/libraries/CBLib/CBLib/Core/CBLib.php' ) ) || ( ! file_exists( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' ) ) ) { return; } include_once( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' ); cbimport( 'cb.html' ); $user = CBuser::getMyUserDataInstance();

If CB API is already loaded you'll only need to call the CBuser usage.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
Last edit: 8 years 6 months ago by krileon.

Please Log in or Create an account to join the conversation.

  • fribse2011
  • fribse2011
  • OFFLINE
  • Posts: 921
  • Thanks: 79
  • Karma: 8
8 years 6 months ago #281028 by fribse2011
Thankyou Kyle

Ok, the first was wrong, but as I only need the user object, to first read the values, and secondly, write values to, is the second option I've used ok, or is that wrong as well, or is the code you've written more efficient?

Best regards
Fribse

Frømandsklubben Nikon, www.nikondyk.dk
We're a volunteer driven diving club in Ishøj, Denmark.
Har du brug for en dykkerklub der rummer alle, så kom ned til os.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48460
  • Thanks: 8280
  • Karma: 1443
8 years 6 months ago #281059 by krileon
What I've provided is the correct up to date usage. Your usage is older usage where you're having to manually supply the view user id where getMyUserDataInstance handles and caches it automatically.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: nant

Please Log in or Create an account to join the conversation.

  • fribse2011
  • fribse2011
  • OFFLINE
  • Posts: 921
  • Thanks: 79
  • Karma: 8
8 years 6 months ago - 8 years 6 months ago #281078 by fribse2011
I see, if I then enter this code, as I understand it that is what it should be:
Code:
<?php Global $_CB_framework; if ( ( ! file_exists( JPATH_SITE . '/libraries/CBLib/CBLib/Core/CBLib.php' ) ) || ( ! file_exists( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' ) ) ) { return; } include_once( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' ); cbimport( 'cb.html' ); $cbUser = CBuser::getMyUserDataInstance(); if ( ! $cbUser ) { $cbUser =& CBuser::getInstance( null ); } $user =& $cbUser->getUserData(); $form->data['navn1'] = $user->name ; $form->data['email1'] = $user->email ; $form->data['mobil1'] = $user->cb_cell ; $form->data['adresse1'] =& $user->cb_adresse ; $form->data['post1'] = $user->cb_postnummer ; ?>
I get this message:
Call to undefined method CB\Database\Table\UserTable::getUserData()
What have I misunderstood?
Oh, wait a minute, the object is already established there, so I don't need the last $cbUser->getUserData() do I, as that is outdated...

Best regards
Fribse

Frømandsklubben Nikon, www.nikondyk.dk
We're a volunteer driven diving club in Ishøj, Denmark.
Har du brug for en dykkerklub der rummer alle, så kom ned til os.
Last edit: 8 years 6 months ago by fribse2011.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum