Can CakePHP automatically create tables from models?

In python :: Pylons, I can execute the setup-app command and it will look at my models and issue the corresponding CREATE TABLE or CREATE INDEX ddl for my specific database.

it seems like this will be a feature of CakePHP, but it's hard for me to find it.

In fact, I see this in the manual: "You can create your database tables as usual. When you create model classes, they will automatically match the tables you created."

what makes me think that this does not exist?

+3
source share
2 answers

, - , , . .

+2

. , YourModel- > query(). , . CakePHP 2.x, , 1.3.

, . , .

$dataSource = ConnectionManager::getDataSource('your DB');
if(!in_array($tableName, $dataSource->listSources()){
    $this->createYourTableFunction();
}

createYourTableFunction MyModel- > query(). SQL. table false, .

$YourModel = new Model(array('table' => false, 'name' => 'YourModel', 'ds' => 'Your DB'));
$YourModel->query('SQL instruction string');
0

Source: https://habr.com/ru/post/1759057/


All Articles