首页 > 解决方案 > 如何在codeigniter中从一个页面重定向到另一个页面

问题描述

我不知道如何做这个 codeignitor 概念。
如果我单击链接,如何将一个页面重定向到另一个页面?

Main1.php

        <?php 

            class Main1 extends CI_Controller { 

                public function index() { 
                    //Load the URL helper
                    $this->load->helper('url'); 

                    //Redirect the user to some site
                    redirect('http://localhost/CodeIgniter/index.php/Main'); 

                   $this->load->view('test1'); 
                } 
            } 
        ?>

test1.php

    <!DOCTYPE html>
    <html>
        <head>
            <title>view page</title>
        </head>
        <body style="padding-top:50px; padding-left:300px">
                <h1 style="color:red"> Without Extension </h1>
                <a href="">Visit With Extension Example</a>
        </body>
    </html>

主文件

    <?php 

        class Main extends CI_Controller { 

            public function index() { 
                $this->load->view('test.html'); 
            } 
        } 
    ?>

测试.html

    <!DOCTYPE html>
    <html>
        <head>
            <title>view page</title>
        </head>
        <body style="padding-top:50px; padding-left:300px">
                <h1 style="color:red"> With Extension </h1>

        </body>
    </html>

标签: phpcodeigniter

解决方案


你可以使用redirect(); 下面给出的东西。

redirect('controllerName/methodName','refresh'); 

或者,如果您想在同一个控制器中重定向。

$this->methondName;

你的代码应该是这样的

 <?php 

    class Main1 extends CI_Controller { 

        public function index() { 
            //Load the URL helper
            $this->load->helper('url'); 

            //Redirect the user to some site
            redirect('Main/index','refresh'); 

        } 
    } 
?>

推荐阅读