在重定向之前将数据从控制器功能传递到控制器功能

问题描述:

I am using codeigniter I have an edit page which shows me all information of a vacancy. The (Vacancy) controller method to load this view looks like this, it makes sure all data is preloaded.

public function editVacancy($vacancyid)
    {
        $this->is_logged_in();
        $this->load->model('vacancy/vacancies_model');

        // Passing Variables
        $data['title'] = 'Titletest';
        $data['class'] = 'vacancy';

        $orgadminuserid = $this->vacancies_model->getOrgAdminUserId($vacancyid);

        if ((!is_null($orgadminuserid)) && ($this->auth_user_id == $orgadminuserid[0]->user_id)) {
            $data['vacancyid'] = $vacancyid;
            $data['vacancy'] = $this->vacancies_model->get($vacancyid);
            $data['test'] = $this->session->flashdata('feedbackdata');

            $partials = array('head' => '_master/header/head', 'navigation' => '_master/header/navigation_dashboard', 'content' => 'dashboard/vacancy/edit_vacancy', 'footer' => '_master/footer/footer');
            $this->template->load('_master/master', $partials, $data);
        }
    }

In this view i have different forms for updating different sections. Every form submit goes to a different method in my 'Vacancy' controller.

    public function saveGeneralInfo()
        {
            $this->is_logged_in();
            $this->load->model('vacancy/vacancies_model');

            $vacancyid = $this->input->post('vacancyid');
            $vacancyUpdateData = $this->vacancies_model->get($vacancyid);

                $result = $this->vacancies_model->update($vacancyid, $vacancyUpdateData);
                if ($result) {
                    $feedbackdata = array(
                       'type'  => 'alert-success',
                       'icon'     => 'fa-check-circle',
                       'title' => 'Success!',
                       'text' => 'De algemene vacature gegevens zijn geupdate.'
                  );
                      $this->session->set_flashdata('feedbackdata', $feedbackdata);
                      redirect("dashboard/vacancy/editVacancy/" . $vacancyid);
                }
            }

    }

Where I indicated in my code "//HERE ..." is where I would want the feedback message parameter to pass on to my 'main controller method' which loads the view with the prefilled data. (editVacancy).

Is there a clean way to do this?

EDIT:

I tried using flashdata, i updated the code to have the flashdata inserted.

However when i do a var_dump($test); in my view, it remains null.

EDIT 2: I noticed when i put my $_SESSION in a variable in my editVacancy controller method (which is being redirected to) and var_dump it in my view that this does not contain the ci_vars with the flashdata in.

Instead of using set_header you can use simple redirect function for it.

redirect("dashboard/vacancy/editVacancy/".$vacancyid);