Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
600 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 Reply

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...