cakephp - get table names and its column details

杀马特。学长 韩版系。学妹 提交于 2019-12-23 17:15:25

问题


Does anyone knows how to get table name from model name? Also I want to get all column names and its types of that model/table name. Is it possible to get such details of given model name?

Thanks.


回答1:


Table Name

To get the table, see

$this->Model->table

Or check the model for the class variable $useTable. If that's undefined, then you can infer it from the name of the model:

$tableName = Inflector::tableize($this->Model->alias);

See the Inflector documentation for similarly useful methods.

Columns

Take a look at the schema method of the Model class. For example:

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


来源:https://stackoverflow.com/questions/7709743/cakephp-get-table-names-and-its-column-details

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!