如何在重定向中发送参数- PHP编码器


how to sent parameter in redirect - php codeigniter

下面的代码给出了一个错误。我想调用一个函数,并传递一个参数给它与php codeigniter。

redirect(base_url() . 'MainController/Student_Login($user_email)')

这里MainController是控制器名,Student_Login是函数$user_email是一个保存用户邮箱id的变量。我也试过通过url发送它。例如

redirect(base_url() . 'MainController/Student_Login/.$user_email.')

请帮。

不需要为base_url添加redirect。

试试吧

redirect('mainController/Student_Login/'.$user_email)

user_email时,您将收到student_Login函数

中的参数

您可以通过会话传递它。如果你希望它只在下次请求时可用,把它放在会话flash数据中。

第一控制器

public function method1()
{
    // if not loaded session library in APPPATH . 'config/autoload.php' load it in here
    $this->session->set_flashdata('user_email', $user_email);
    redirect('secondcontroller/method2', 'refresh');
}

第二控制器

public function method2()
{
    // if not loaded session library in APPPATH . 'config/autoload.php' load it in here
    $user_data = $this->session->flashdata('user_email');
    // when flash data is set, after this request it will be unset from $_SESSION array
}

用它来代替base_url()

redirect('MainController/Student_Login/'.$user_email);

方法中使用

function Student_Login($user_email){
    echo $user_email;
    //...
}

试试这个

redirect(base_url() . "MainController/Student_Login/" . $user_email);

$url = base_url() . "MainController/Student_Login/" . $user_email;
redirect($url);

试试这个

 redirect(base_url()."MainController/Student_Login/".$user_email);