Buy Now
Sign in

Syntax to access user's informations in a php function

FloB , January 29 at 14:19
Answered
F
FloB
Hello,

I need to display some information via CCv6.
The informations are differents if the user is logged in, is a special logged in user or is not logged.
So I've got 3 different tables :
table 1 : access public allowed
table 2 : access registred allowed
table 3 : access only few registred users according to the user_id

I would like to use a php function in order to display the wanted table, but I don't know how to access the user's information in the php function.
I've tried $this->get('user') or echo "{user:id}" without success.

Could someone help me with the syntax please?
Florence
F
FloB
I have managed to retreive the user's informations with
$user = \JFactory::getUser();

However, I can't have the table displayed because the {fn:read_data2}{view:table1} below isn't "translated" when I access the event :
Events
Index
{fn:read_data1}
{fn:php1}
{var:php1}

Views
table1 : to display the read_data2 informations
Functions
read_data1 : to find the user_id for wich the table 1 should be visible
read_data2 : to find the informations displayed in the table1
php1 :
$user = \JFactory::getUser();
$list_userid=$this->get('read_data1');
if(in_array($user->id,$list_userid){
return "{fn:read_data2} {view:table1}";
}else{
//other informations
}


The php1 function is working well because the index event shows either "{fn:read_data2} {view:table1}" or the other informations, but instead of reading "{fn:read_data2} {view:table1}", I would have the table1 displayed...

Thanks for the help,
CCv6 is really amazing, but quite different from CCv5
admin

Hi FloB,

Glad you like v6

In order to process shortcodes inside PHP code you need to use the following syntax:

return $this->Parser->parse("{view:table1}");

Best regards

Max
If your main question got answered then please mark the answer using the button!​

Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
F
FloB

Thanks a lot.​