2015-03-03 66 views
1

我想知道是否有可能只显示CodeIgniter中的最终调用函数的输出?如何查看codeigniter中的最终输出?

例如,在下面的代码中,当用户处于索引方法(/ goose/index)时,他们将看到来自'foo1'和'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

+0

好..所以你想要调用foo1,但是你不想加载foo1视图..而是你想加载foo2视图...就是你所有的doi恩,你只是加载意见?有没有需要传递的数据? – CodeGodie 2015-03-03 02:05:14

+0

是的,没错。只是加载最后的视图,在这种情况下是foo2() – 2015-03-03 02:26:38

+0

那么为什么下面的答案不起作用?有没有其他限制或限制? – CodeGodie 2015-03-03 02:40:21

回答

1

如果你把一个参数在你的函数它应该工作

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

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

    $this->foo2();   
} 
+0

谢谢@borracciaBlu – 2015-03-03 02:44:20

+0

@VeeDee这将加载''/ goose/foo1''的视图,它只会为''/ goose/index''加载视图'foo2' – 2015-03-03 03:22:28

0

我想你想这样

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

}

+0

我不认为他想要那样。 – epynic 2015-03-03 05:53:24