在cakephp中有一種簡單的方法來獲取特定表格列表的表格數組數組嗎?例如,我想要表a,b,d,f和z的表模式;另外,有沒有辦法獲得所有表的模式數組?通過調用cakephp獲取表格列表
$db =& ConnectionManager::getDataSource('default');
或
$db =& $this->User->getDataSource(); // or any other model
然後你就可以得到所有的表:
在cakephp中有一種簡單的方法來獲取特定表格列表的表格數組數組嗎?例如,我想要表a,b,d,f和z的表模式;另外,有沒有辦法獲得所有表的模式數組?通過調用cakephp獲取表格列表
$db =& ConnectionManager::getDataSource('default');
或
$db =& $this->User->getDataSource(); // or any other model
然後你就可以得到所有的表:
獲取數據源,通過
$db->listSources()
,並獲得架構表,說「產品」
$db->describe('products');
但是,將字符串傳遞給describe
僅在CakePHP 2.0中爲,1.3需要模型對象。
我使用1.3,所以我可以做$ this-> loadModel($ modelname); $ db-> describe($ this - > $ modelname)對不對? – LordZardeck 2012-01-29 22:26:21
是的,應該工作 – ori 2012-01-29 22:31:16
對不起,接受這麼長時間。這工作就像一個魅力! – LordZardeck 2012-02-01 18:57:33
試試這個
pr($this->Model->schema());
所有的表可以用'蛋糕模式傾倒產生蛋糕上的控制檯-f'命令。不知道具體的表格。 – Oldskool 2012-01-29 20:07:03
有無論如何要在控制器中調用這個? – LordZardeck 2012-01-29 21:38:22
您可能可以使用CakeSchema類:http://api20.cakephp.org/class/cake-schema – Oldskool 2012-01-29 21:49:09