Jump to content

How to check if user is admin when overriding controller function


Equity

Recommended Posts

Hi,

Could use some help figuring out a conditional to check if user is admin if not load something else for a JReviews controller.php template override. Have tried calling the Jfactory and S2Object::make('auth');. Its all confusing to me.

<?php
defined('MVC_FRAMEWORK') or die;
//use Joomla\CMS\Factory;
//use JFactory::getApplication();

  Function myFunction()
  {
    if (defined('MVC_FRAMEWORK_ADMIN')) return;
      
      //$auth = S2Object::make('auth');
      //$auth = Factory::getUser();

      If ($auth->admin && $auth->connected)

            //do something or output something


      elseif !($auth->admin && $auth->connected) {

            //do something or output something
      }
          
     //Or this example

      If ($auth->isAdmin && $auth->connected)  {

            //do something or output something

      elseif !($auth->isAdmin && $auth->connected) {

           //do something or output something
      }
    }
  }

Thanks!
DanielH

Edited by Equity
Link to comment
×
×
  • Create New...