Welcome Guest, Not a member yet? Register   Sign In
reusing common methods + redirect to current page
#10

[eluser]allibubba[/eluser]
what i ended up with for my add to cart functionality is this:
Code:
header('location:'.$_SERVER['HTTP_REFERER']);

this works ok since you are on a product page, adding to cart just sends you back to where you were. though i think for production purposes i would facilitate the add to cart function via ajax.

as for my user redirect, which does use flash data, and seems to finally be stable:
im my user_model;
Code:
function restrictUser($role){
        # does user have admin rights?
        if($this->session->userdata('level') != $role){
            
            $this->session->set_flashdata('requested_page',$this->uri->uri_string());
            if($this->session->userdata('level')){
                //redirect();
                $this->session->set_flashdata('message','<p class="error">You do not have sufficient privileges.</p>');
                redirect('user/login');
            }else{
                $this->session->set_flashdata('message','<p class="error">You are not logged in..</p>');
                redirect('user/login');
            }
        }
    }
and i call in my restricted controller, load my user_model, and then in the constructor:
Code:
$this->User_model->restrictUser('admin');
this checks if user is logged in and if they have admin rights. redirect is stored in flash data and passed to a redirect in my login function, i added custom messages as well to alert users to the reason they were bounced back to login.

in my login function i needed to keep the flash data alive:
Code:
$this->session->keep_flashdata('requested_page');
$this->session->keep_flashdata('message');
and on passing login, i simply bounce user back to page stored in flash data.

as for the referrer, i haven't noticed any problems.

working on creating a user library now, when i make some solid progress i'll post back. hope this helps somebody out


Messages In This Thread
reusing common methods + redirect to current page - by El Forum - 07-14-2008, 12:32 PM
reusing common methods + redirect to current page - by El Forum - 07-15-2008, 05:25 AM
reusing common methods + redirect to current page - by El Forum - 07-15-2008, 06:05 PM
reusing common methods + redirect to current page - by El Forum - 07-15-2008, 08:37 PM
reusing common methods + redirect to current page - by El Forum - 07-16-2008, 12:22 PM
reusing common methods + redirect to current page - by El Forum - 07-16-2008, 12:55 PM
reusing common methods + redirect to current page - by El Forum - 07-21-2008, 04:40 PM
reusing common methods + redirect to current page - by El Forum - 07-21-2008, 05:03 PM
reusing common methods + redirect to current page - by El Forum - 07-21-2008, 05:08 PM
reusing common methods + redirect to current page - by El Forum - 07-31-2008, 02:39 PM
reusing common methods + redirect to current page - by El Forum - 01-19-2009, 01:29 PM
reusing common methods + redirect to current page - by El Forum - 09-17-2010, 10:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB