本文介绍了cakephp获取表的列表的模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在cakephp中有一个简单的方法来获取表模式的数组,以获取特定表的列表?例如,我想要一个表模式表a,b,d,f和z;
Is there an easy way in cakephp to get an array of tables schema for a list of specific tables? For example, i want a table schema for table a, b, d, f, and z; Also, is there a way to get a schema array of all the tables?
推荐答案获取一个数据源,通过:
Get a datasource, by:
$db =& ConnectionManager::getDataSource('default');或
$db =& $this->User->getDataSource(); // or any other model然后您可以通过调用以下方式获取所有表:
Then you can get all the tables by calling:
$db->listSources()b $ b
获取表的模式,例如products
And get the schema for a table, say "products"
$db->describe('products');但是,传递一个字符串到 describe 仅在CakePHP 2.0 中,1.3需要模型对象。
However, passing a string to describe is only in CakePHP 2.0, 1.3 requires a model object.
更多推荐
cakephp获取表的列表的模式
发布评论