简体   繁体   中英

can i use same controller for user and admin?

i am making a online book store in codeigniter.when user logging in, i am using

 localhost/folder/index.php/User_controller.

my qustion is when admin is logging in one extra menu should come for approval, rest of the view is same as that of user.so what should i do,when i make seperate controller in different application folder,i have to run different in url, ie localhost/foldername/admin.php/admin_controller .i am really confused.please help............

You can build a custom library where you may write function for checking if_admin() . After that you can use this function in any view file or controller and load content as required.

Create Custom Library

So doesn't need to create different controller for admin. Just check with is_admin() in menu to load extra menu.

A demo method is look like (in custom library)

public function is_admin() {
    $type = (int) $this->CI->session->user_type;
    if ($type === 4) {//4 is admin type
        return TRUE;
    } else {
        return FALSE;
    }
}

Now check in view file as

if($this->custom_lib->is_admin()){
   //load extra menu items
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM