Advertisement:

Author Topic: helpers  (Read 704 times)

jonathan21_

  • Newbie
  • *
  • Posts: 6
helpers
« on: October 16, 2017, 04:30:52 pm »
Hello everyone ;)
I have not really found the answer to my question so I allow myself to create a subject :)

I'm doing two dashboards for two different types of users. The only problem is that I do not understand why I do not return helpers on some pages ...

For example, this code returns an EMPTY result when I use it on some pages:
Code: [Select]
<?php print_r(osc_user()); ?>

On other it's impeccable;) Any ideas?
Thank you !
« Last Edit: October 17, 2017, 10:22:57 am by jonathan21_ »

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: helpers
« Reply #1 on: October 16, 2017, 04:43:00 pm »
Hi,

Depending on the page, osc_user() might contain data for the current logged in user (User Dashboard), or data for the user that published the ad (item.php)... and more scenarios (Public Profile, for example).

So you need to change that where it's not working as you want:

Code: [Select]
$userId = osc_logged_user_id();
View::newInstance()->_exportVariableToView('user', User::newInstance()->findByPrimaryKey($userId));

Or $userId = osc_item_user_id();

etc

Regards

jonathan21_

  • Newbie
  • *
  • Posts: 6
Re: helpers
« Reply #2 on: October 16, 2017, 05:23:53 pm »
Good, phanks !

jonathan21_

  • Newbie
  • *
  • Posts: 6
Re: helpers
« Reply #3 on: October 16, 2017, 11:49:52 pm »
Hello again !
Then, your code works correctly however it creates strange behaviors on the site :)
The number of ads and the registration date are no longer displayed on the ad details. The ad counter is simply zero: / Ideas? Thank you !

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: helpers
« Reply #4 on: October 17, 2017, 12:46:20 am »
Likely you have introduced this in a page that already uses User data. Just after you're done with your custom code, delete the User data:

Code: [Select]
View::newInstance()->_erase('user');
Regards

jonathan21_

  • Newbie
  • *
  • Posts: 6
Re: helpers
« Reply #5 on: October 17, 2017, 10:20:50 am »
I had not seen your answer so I looked for a solution and I use this code:
Code: [Select]
<?php
if ( osc_user_field('b_company') == "" ) {
        
$juc_userId osc_logged_user_id();
        
View::newInstance()->_exportVariableToView('user'User::newInstance()->findByPrimaryKey($juc_userId));
}
?>

Is this code correct?

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: helpers
« Reply #6 on: October 17, 2017, 01:18:03 pm »
Hm... This can be tricky.  ;D

What page is this and what do you want to achieve? Please elaborate...

Regards

jonathan21_

  • Newbie
  • *
  • Posts: 6
Re: helpers
« Reply #7 on: October 17, 2017, 01:39:36 pm »
I put this code in the base.php page of my theme which is called everywhere. Perhaps it would be possible to have a cleaner condition before instantiating the class?
a kind of if exist?

I recall that I translate with Google because my English level is very low lol.

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: helpers
« Reply #8 on: October 17, 2017, 01:48:16 pm »
Huh, then I think best you can do is to first backup data for Possible active User, do your thing and then restore the backup:

Code: [Select]
// Backup original User data
$currentUserView = __get('user');

$juc_userId = osc_logged_user_id();
View::newInstance()->_exportVariableToView('user', User::newInstance()->findByPrimaryKey($juc_userId));

// Your custom code here

// Restore original User data
View::newInstance()->_exportVariableToView('user', $currentUserView);