Welcome Guest, Not a member yet? Register   Sign In
Codeigniter4 How to switch controller based on user auth group
#1

(This post was last modified: 06-26-2024, 02:30 AM by sarath_unrelax.)

Hello,


I have two view files: one for users and another for admins. Here is my current route:

PHP Code:
$routes->get('dashboard/index'' Dashboard::index'); 


I want to change the view file based on the user's group. If
Code:
auth()->user()->inGroup("admin")
, it should use the "dashboard/admin" view; otherwise, it should use the "dashboard/index" view.
How can I achieve this?
Reply
#2

Create folders admin, user and concat in controller $group . "dashboard/index" or try if/else in view template
Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply
#3

(This post was last modified: 06-26-2024, 06:33 AM by luckmoshy.)

PHP Code:
public function Redirect(): string
{
    if( auth()->user()->inGroup('admin')){
        return view '/admin' );
      elseif(auth()->user()->inGroup('user') ) 
{
return 
view '/user' );
}
        

   

Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply




Theme © iAndrew 2016 - Forum software by © MyBB