Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Can';t重定向到codeigniter下同一控制器上的不同方法_Php_Codeigniter_Redirect_Codeigniter 2 - Fatal编程技术网

Php Can';t重定向到codeigniter下同一控制器上的不同方法

Php Can';t重定向到codeigniter下同一控制器上的不同方法,php,codeigniter,redirect,codeigniter-2,Php,Codeigniter,Redirect,Codeigniter 2,假设我有一个带有两个方法的控制器,我想从method1重定向到method2,但由于以下错误,这是不可能的: Chrome:Error 310(net::ERR\u太多重定向):重定向太多。 Firefox:页面未正确重定向 我怎样才能解决这个问题 class Site extends CI_Controller { function method1() { { ... Some Code ... } redirect('site/me

假设我有一个带有两个方法的控制器,我想从method1重定向到method2,但由于以下错误,这是不可能的:

Chrome:
Error 310(net::ERR\u太多重定向):重定向太多。

Firefox:
页面未正确重定向

我怎样才能解决这个问题

class Site extends CI_Controller {
       function method1() {
           { ... Some Code ... }
            redirect('site/method2');
        }

        function method2() {
            { ... Rest of the code  ... }
        }
}

你可以这样做

class example extends CI_Controller{

    public function __construct()
    {
        parent::__construct();
            }

            public function method1(argument1)
            {
                   //your code
            }


            public function method2(argument2)
           {
               //your code

               $this->method1(arg);

                        or

              echo '<script language="javascript">top.location.href="'.ROOT_FOLDER.'/example/method1/'.$argument.'";</script>';
           }
类示例扩展CI_控制器{
公共函数构造()
{
父项::_构造();
}
公共功能方法1(论证1)
{
//你的代码
}
公共功能方法2(论证2)
{
//你的代码
$this->method1(arg);
或
echo'top.location.href=“.ROOT_文件夹”。/example/method1/”.$argument.“;”;
}

问题是,您必须检查当前的
url
,如果它与您计划重定向的url相同,则不要重定向。以下是一个示例

class Site extends CI_Controller {
       function method1()
       {
           if(// all is GOOD)
           {
              $this->redirect('site','method2','args');
           }else{
              // Do something if the code fails
           }
        }

        function method2()
        {
           if(// all is GOOD)
           {
              $this->redirect('site','method1','args');
           }else{
              // Do something if the code fails
           }
        }

        function check_redirect($controller,$method,$args)
        {
           if($this->router->class !== $controller AND $this->router->method !== $method)
           {
              redirect($controller.'/'.$method.'/'.$args);
           }
        }
}
method1
重定向到
method2
时,页面没有正确重定向
发生,然后当转到
method2
时,页面再次重定向回
method1
完成一个无终止的重定向循环


这只是基本的,没有设置任何错误处理。

我们不会假设任何情况。请发布您尝试过的内容?好的,我尝试保持简单。添加了代码,谢谢可能是method2重定向回或调用method1。如果没有更多代码,就无法判断。请将您的htaccess代码放在此处谢谢,但我无法使用
$this->method1
在这里。我正在寻找一种使用redirect()实现此目的的方法。您到底想要什么?您想要重定向到调用方法中的视图吗。。。。。。