如何在codeigniter中只查看最终输出


How do you view only the final output in codeigniter?

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

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

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

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');
}

}