2015-03-03 69 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