Problem: We have a public menu, and restrict it for non logged in users, if we use joomla menu access level restriction, and set access to registered, it will hide menu for public, so we have to write code to achieve our requirements.
Solution:
Consider following code and insert into HTMLView file.
// Import required classes
use Joomla\CMS\Factory; use Joomla\CMS\Router\Route; use Joomla\CMS\Uri\Uri; // Define redirect after login $returnUrl = base64_encode('https://b2c.com.pk/list-business'); $loginUrl = Route::_('index.php?option=com_users&view=login&return=' . $returnUrl, false); // Redirect non-logged-in users to login page $user = Factory::getUser(); if ($user->guest) { Factory::getApplication()->redirect($loginUrl); exit; }
Still need help! no problem, feel free to contact us Today