little php help needed

joit

Active Member
Hi,

I want to display some content just for certain user groups in an article. This worked great for guest user groups but it doesn't seam to work for others:
PHP:
{source}
<?php
$user = JFactory::getUser();
if ($user->get('vendor', 0))
{
// vendor
echo '<p>
jkhgjfdkhg
</p>';
}
?>
{/source}

Any ideas?

Thanks
Hannes
 
What do you expect to get with $user->get('vendor',0)?
Vendor is no column in #__users
 
You'll need to use either getAuthorisedGroups() or getAuthorisedViewLevels(), depending on whether you really mean "groups" or view levels.

So if you 'vendor' group is ID 123 ...

PHP:
$groups = JFactory::getUser()->getAuthorisedGroups();
if (in_array(123, $groups)) {
   // echo your stuff
}

If you really mean view levels, not groups (which is what you should use for controlling access), then just substitute getAuthorisedViewLevels() and the view level ID in the above.

-- hugh
 
Thanks guys, this works great!
the only problem is, that I have links to menus in my echo stuff and these links get kicked out. This is maybe a problem of sourcerer. Any idea how I could bring them back?

Edit: it seams that all kind of formatting gets killed
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top