Vajnh Adrienne
Vajnh Adrienne

Reputation: 11

Redirecting URL - Codeigniter

I needed help in redirecting my page depending on your current page.

So basically,

I have a navigation bar with a notification dropdown and in that dropdown, I have the option to accept and delete.

Let's say I'm in my profile page and I want to click delete from the notification, I wan't to just stay in the profile page. And if I'm in the settings page I click delete, it will still stay in the settings page.

Any idea how to do this?

This is what Ive done so far.

function delete_notif(){
    $id = $this->uri->segment(3);
    $pid = $this->uri->segment(4);
     $this->admin_model->delete($id, $pid);

    $profile = 'profile';
    $settings = 'settings';


    if($id = $profile && $id != $projects) {
        redirect('manager/profile');
    } else if ($id != $settings && $id = $projects) {
        redirect('manager/all_projects');
    }
}

Upvotes: 1

Views: 66

Answers (1)

Mateusz Wojtuła
Mateusz Wojtuła

Reputation: 229

You have incorrect compare in "if" statement - there should be "==" instead of "=". But I think it will be better to write it like that:

function delete_notif(){
    $id = $this->uri->segment(3);
    $pid = $this->uri->segment(4);
    $this->admin_model->delete($id, $pid);

    switch($id) {
        case 'profile':
            redirect('manager/profile');
            break;
        case 'settings':
            redirect('manager/all_projects');
            break;
        default:
            redirect('manager/profile');
            break;
    }
}

Upvotes: 2

Related Questions