dpxw7293 2016-10-07 12:52
浏览 71
已采纳

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

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.

  • 写回答

1条回答 默认 最新

  • duanqiaoren9975 2016-10-07 13:24
    关注

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

    redirect("dashboard/vacancy/editVacancy/".$vacancyid);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口