Using all memory with this code

fribse 25 Apr, 2016
In v4 I have this code to prepopulate my form with userdata:
global $_CB_framework, $mainframe;
if ( defined( 'JPATH_ADMINISTRATOR' ) ) {
	if ( ! file_exists( JPATH_ADMINISTRATOR . '/components/com_comprofiler/' ) ) {
		echo 'CB not installed!';
	include_once( JPATH_ADMINISTRATOR . '/components/com_comprofiler/' );
} else {
	if ( ! file_exists( $mainframe->getCfg( 'absolute_path' ) . '/administrator/components/com_comprofiler/' ) ) {
		echo 'CB not installed!';
	include_once( $mainframe->getCfg( 'absolute_path' ) . '/administrator/components/com_comprofiler/' );
$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;

But when I try to use it in v5 it exhausts the memory.
Am I doing something wrong?
GreyHead 26 Apr, 2016
Hi Fribse,

Yes something is wrong - though I'm not clear what is.

I assume that you have CFv5.0.11 installed and not 5.0.1 ?

Some of the & you have are unnecessary with more recent versions of PHP and declaring $mainframe as global might be a problem.

I suggest that you set your site Error Reporting to Maximum; then comment out all of your code and check, then remove the comments bit by bit (keeping the logic correct) until you can pin down where the error is caused. Most often it is some kind of loop but I don't see any obvious one here.

fribse 26 Apr, 2016
Yes it's 5.0.11, sorry for the typo.
I'll go and ask Community Builder, because I don't have a clue on what is the 'right' way of getting a CB user object.
fribse 27 Apr, 2016
It seems that the code needed has changed with the later CB's.

I got a result with another tutorial, but Kyle gave me a third suggestion, so now I need to find out which is best.
fribse 29 Apr, 2016
This is the new way of getting a CB user object:

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

The proper way of prepopulating a field is this way (name is called navn1 in the form)

$form->data['navn1'] = $user->get( 'name' ) ;

This seems to work as it should
This topic is locked and no more replies can be posted.