duanchuopi2298 2015-03-12 05:23
浏览 81

如何在codeigniter控制器类中使用重定向?

Can any one tel me how to use redirect in controller class.

I am wrote below code:

Controller:-

<?php
class Login extends CI_Controller {
public function result()
    {
    $name = $this->input->post('name');
    $email = $this->input->post('email');
    $this->index();
        redirect('/success', 'location');
    }   
}

view:-

success.php

<?php
   echo "Success page";
?>

It shows error message 404 Page Not Found. I have load all required helper classes in autoload class.

  • 写回答

3条回答 默认 最新

  • doudun3910 2015-03-12 05:29
    关注

    In Codeigniter , redirect method takes 3 parameters.

    redirect('/controller_name/method_name', 'location', 301);
    

    First parameter is the uri path which you want to redirect. The second parameter is optional and takes "location" method (default) or the "refresh" method. The third optional parameter is status code. You can check detail on documentation.

    Edit

    function success () {
        $data["message"] = "Success";
        $this->load->view("success", $data);
    }
    

    views/success.php

    <?php echo $message; ?>
    

    You have to pass data in array because codeigniter use extract method to pass value in view so that you can use arrary key as variable.

    Hope it will be useful for you.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
  • ¥15 算法题:数的划分,用记忆化DFS做WA求调
  • ¥15 chatglm-6b应用到django项目中,模型加载失败
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。
  • ¥30 win c++ socket
  • ¥15 C# datagridview 栏位进度