2017-03-17 110 views
-2

如何將數據從控制器傳遞到CodeIgniter中的視圖?如何將Controller中的數據傳遞給CodeIgniter中的View?

控制器

<?php 
defined('BASEPATH') OR exit('No direct script access allowed'); 
class Hello extends CI_Controller {  
    public function index() 
    { 
     $data['hello']= "helloooo"; 
     $this->load->view('hello_world'); 
    } 
} 
+3

請使用谷歌在控制器笨... –

+1

https://www.codeigniter.com/user_guide/general/views.html#adding-dynamic-data-to-the-view – user4419336

+0

的閱讀文檔'$ this-> load-> view('hello_world',$ data);'在視圖中'echo $ hello' –

回答

1
<?php 
defined('BASEPATH') OR exit('No direct script access allowed'); 
class Hello extends CI_Controller {  
    public function index() 
    { 
     $data['hello']= "helloooo"; 
     $this->load->view('hello_world',$data); 
    } 
} 

在你看來

echo $hello; 

,並在視圖頁面程序hello_world參觀https://www.codeigniter.com/user_guide/

0
<?php 
defined('BASEPATH') OR exit('No direct script access allowed'); 

class Hello extends CI_Controller { 

    public function index() 
    { 
     $data['hello']= "helloooo"; 
     $this->load->view('hello_world',$data); 
    } 
} 

<?php 
echo $hello; 
?> 
0

加載視圖時將數據作爲參數傳遞。

$data['hello']= "helloooo"; 
$this->load->view('hello_world', $data); 
相關問題