Welcome Guest, Not a member yet? Register   Sign In
Under Maintenance - Need help
#1

[eluser]IamPrototype[/eluser]
I want to code it so my admins can access the front end under maintenance like they can access back-end. I know how to build it, but I'd like to know if this code I'll show you know is the best way to do it again only focus on the FIRST if() that checks if the user is logged and admin. Is there a better way to do it? Checking logged in and admin, maybe put it all together in a single line code.

Code:
if( logged_in() AND $this->user->item->('role') == 1) {
        if( $this->preference->item('maintenance_mode') AND $this->uri->rsegment(1) != 'auth')
        {
            redirect('auth/maintenance','location');
        }
        }
#2

[eluser]Dam1an[/eluser]
What you could do, is create a function is_admin() which check if they're logged in and admin status
If it fails the logged in check, it returns false, if they're logged in, the then returns if they're admin or now

Code:
function is_admin() {
    if(!$this->session->userdata('logged_in')) return false;
    
    return $this->user->item->('role') == 1;
}

You can then just do
Code:
if(is_admin()) {
    // Adming stuff
}
#3

[eluser]IamPrototype[/eluser]
Like check for maintenance, if true, check if your admin, if yes, you'll have access to the site if your not an admin, you'll be redirected to the maintenance site. Would that be a good way on how to do it? Or still.. will there be a better and much safer way?




Theme © iAndrew 2016 - Forum software by © MyBB