Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
599 views
in Technique[技术] by (71.8m points)

cakephp 3.0 using tableprefix?

Moving on from a cakephp 2 application, I am stuck on trying to use $tablePrefix in my models. Is this still available in Cake 3? Or how can I use something else (please explain).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Table prefixes are gone for now. There is an open PR, however it's not clear at this point when, and if at all this is going to make it:

https://github.com/cakephp/cakephp/pull/4505

As mentioned by Lorenzo in the comments, an alternative might be using events to initialize models with a prefixed table name:

For people still wanting support for prefixes in their tables, there is a way to support it using events. This will probably work for all table operations. Add it to your bootstrap.php file:

EventManager::instance()->on('Model.initialize', function ($event, $instance) {
    $instance->table('prefix_' . $instance->table());
});

https://github.com/cakephp/cakephp/pull/4505#issuecomment-76154855


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...