XF 2.0 Get member ID in widget

AndyB

Well-known member
I'm creating a Member notes add-on and it uses the Member view: sidebar widget.

1513207605927.webp

In my PHP code, I tried using the contextParams but it doesn't work.

PHP:
<?php

namespace Andy\MemberNotes\Widget;

use \XF\Widget\AbstractWidget;

class MemberNotes extends AbstractWidget
{
    public function render()
    {
		// get visitor
		$visitor = \XF::visitor();				

		// check for user group permission
		if (!$visitor->hasPermission('memberNotes', 'view'))
		{
			return;
		}
		
		$member = $this->contextParams['member'];
...


How can I get the member id?

Thank you.
 
I should be more clear. I'm viewing the profile page, for example:

https://xenforo.com/community/members/chris-d.11388/

I would like to get the member ID 11388 using this example.
 
Got it.

PHP:
<?php

namespace Andy\MemberNotes\Widget;

use \XF\Widget\AbstractWidget;

class MemberNotes extends AbstractWidget
{
    public function render()
    {
		// get visitor
		$visitor = \XF::visitor();				

		// check for user group permission
		if (!$visitor->hasPermission('memberNotes', 'view'))
		{
			return;
		}
		
		// get user
		$user = $this->contextParams['user'];

		// get memberId
		$memberId = $user->user_id;
 
Back
Top Bottom