2011-12-29 42 views
0

我有這樣一個控制器:笨裝載庫

<?php if(! defined('BASEPATH')) exit ('No direct script acces allowed'); 

class Halaman extends CI_controller{ 
function __controller(){ 
    parent::controller; 
    $this->load->helper(array('url','form')); 
    $this->load->library('table'); 
} 

function index(){ 
    $this->load->library(array('form_validation')); 
    $this->load->view('view_halaman'); 
} 
function daftar(){ 
      $this->load->model(url); 
    } 
} 

,我有像這裏這樣一個

<!DOCTYPE html> 
<html lang="en"> 
<head> 
<meta charset="utf-8"> 
<title>Pembagian menggunakan validasi!!</title> 
</head> 


<body> 
<h1>Daftar Ulang</h1> 
<?php echo form_open('halaman/daftar'); ?> 
<?php $data=array(
    array('Field','isi data'), 
    array('nama',form_input('user','tulis username')), 
    array('password',form_password('pass','password')), 
    array('email',form_input('email','tulis email di sini')) 
); 
echo $this->table->generate($data); 
?> 
<?php echo form_close(); ?> 

<p><br/>Page rendered in {elapsed_time} seconds</p> 
</html> 

輸入代碼視圖

我所得到的是這樣的一種: error message 我的錯誤在哪裏?即時通訊抱歉,我真的是新手在codeigniter。非常感謝 。

回答

0

$ table不是視圖對象的成員。所以你不能從視圖模板中調用它。您需要將echo $this->table->generate($data);移動到控制器,並將其分配給視圖變量或僅從控制器回顯。

0

我認爲問題在於庫沒有加載(這是紅色內襯框中的錯誤)。當您不遵循CI庫名稱約定時會發生這種情況。該表庫應該爲應用程序/庫/ Table.php和類必須是像成才:

class Table { 
    // Your code 
} 

http://codeigniter.com/user_guide/general/creating_libraries.html

此外,當您加載庫,請使用大寫字母T的名稱:

$this->load->library('Table'); 

Regards,