Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter: change URL after loading a View

I am working on a project which deals with lots of forms. I searched and tried the search results, but none of them worked.

My code view code "uprofile.php" is as follows:

<form class="form-horizontal" method="post" action='<?php echo base_url() . "home/addnewagency" ?>'>
        <div class="form-group">
            <label for="company" class="col-sm-3 control-label">New Agency Name:</label>
            <div class="col-sm-4">
                <input type="text" class="form-control" id="newagency" name="newagency" placeholder="Plase Enter New Agency Name">
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-3 col-sm-9">
                <button type="submit" class="btn btn-primary">Add</button>
            </div>
        </div>
    </form>

My Controller "home.php" code is as follows:

public function addnewagency() {
        $newagency = $this->input->post('newagency');
        $this->dis_model->newagency_model(strtoupper($newagency));
        $this->loadprofile();
    }
    public function loadprofile() {
        $data['inscompanyname'] = $this->dis_model->getcompany();
        $data['agentname'] = $this->dis_model->getagent();
        $data['agencyname'] = $this->dis_model->getagency();
        $data['clientname'] = $this->dis_model->getclient();
        $data['deptname'] = $this->dis_model->getdept();
        $this->load->view('uprofile', $data);
    }

when I submit the form, the control is passed to addnewagency() data gets inserted in the database and the URL is http://localhost/dis/home/addnewagency. After getting back to the calling function, it goes to loadprofile() and loads the view uprofile. But, the URL still remains the same. But, I want it as http://localhost/dis/home/login and also want to pass the data. Does anyone have any idea regarding how to achieve this?

All positive suggestion are welcomed...

Thanks in advance...

like image 528
V15HM4Y Avatar asked Feb 06 '23 17:02

V15HM4Y


2 Answers

Now you are calling $this->loadprofile() within addnewagency(). If you want to change URL, you need to use redirect() function of CodeIgniter.

Replace

$this->loadprofile()     

with below line of code and it will work for you.

redirect(base_url() . 'home/loadprofile');
like image 89
Rukmi Patel Avatar answered Feb 09 '23 19:02

Rukmi Patel


if you want to change the url use redirect(base_url() . 'home/loadprofile'); in your controller addnewagency(); as suggested by others and refer this question to know whether you can send data in redirect function or not, Sending data along with a redirect in CodeIgniter

like image 44
Kamal Lama Avatar answered Feb 09 '23 20:02

Kamal Lama