2013-02-19 61 views
-2

我想從cakephp中的表中獲取列名,我嘗試了下面的代碼,但它不工作。從cakephp中的表中獲取列名

$table_venue = $this->Venue->getColumnTypes(); 
print_r($table_venue); 
//Venue is the model name . 

當我執行上面的代碼,我得到錯誤的Call to a member function getColumnTypes()

,也是我試過下面的代碼

$table_venue = $this->query('Select columnname from venues'); 
print_r($table_venue); 

你能幫助我嗎?提前致謝。

+0

選中此http://stackoverflow.com/questions/6723635/cakephp-error-call-to- a-member-function-getcolumntype – Rikesh 2013-02-19 07:24:24

+0

'在非對象上調用成員函數x意味着'$ this-> Venue'不存在 - 您已經/有的問題是加載/訪問模型。 – AD7six 2015-09-23 08:46:06

回答

-1

,當你做到這一點$table_venue = $this->query('Select columnname from venues');$table_venue = $this->query('Select columnname from venues')->result_array(); 和存儲這$data和回聲$data['columnname']

希望這有助於。

+0

'$ this-> query('從場地中選擇列名') - > result_array();'查詢返回一個數組,這個代碼示例是一個致命錯誤。 – AD7six 2015-09-23 08:43:48

1

在控制器:

debug($this->Model->schema()); 

在模型:

debug($this->schema()); 
0
array_keys($this->Model->getColumnTypes());