您如何只查看 codeigniter 中的最终输出?

How do you view only the final output in codeigniter?

我想知道是否可以在 CodeIgniter 中只显示最终调用函数的输出?

例如,在下面的代码中,当用户使用索引方法 (/goose/index) 时,他们将看到两个视图 'foo1' 和 'foo2' 的输出。

我想实现的是只看到最终视图的输出(即'foo2')。只是想知道是否可以在不使用 redirect() 的情况下做到这一点。

class Goose extends CI_Controller {

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

    public function index()
    {
        $this->foo1();
    }

    public function foo1()
    {           
        $this->load->view('foo1');
        $this->foo2();
        //redirect(base_url('index.php/goose/foo2'));
    }


    public function foo2()
    {       
        $this->load->view('foo2');
    }

}

谢谢。

V

如果你在你的函数中加入一个参数,它应该可以工作

public function index()
{
    $this->foo1(false);
}

public function foo1($flag = true)
{
    if ($flag) {
        $this->load->view('foo1');
    }

    $this->foo2();        
}

我想你想要这样

class Goose extends CI_Controller {

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

public function index()//if user comes by /goose/index it will load both view or call both function
{
    //call both function for index
    $this->foo1();
    $this->foo2();
    //or call only both views
    //$this->load->view('foo1');   
   // $this->load->view('foo2');

   //or call only desired function or view
}

public function foo1()//if user comes with /goose/foo1 will load only foo1 view
{           
    $this->load->view('foo1');       
}
public function foo2()//if user comes with /goose/foo2 will load foo2 view
{       
    $this->load->view('foo2');
}

}