I want to write a plugin, which has its own database tables. Without creating the tables from a schema.php file, I create them manually. Then I want to bake the models for that plugin. But I also want cake bake shell to recognize prefixed table names and understand that they belong to that plugin, so that only prefixed tables are shown in the options of the shell.
To clarify, plugins may have their own schema. So, sometimes table names of different plugins may conflict. In order to avoid any conflicts, I guess table prefixes can be used. Is it possible to use table prefixes for CakePHP plugins? If the answer is yes, then how can I configure table prefix for a plugin? My preference is not to touch app/Config/database.php file. Instead, it would be better to set any configuration in the plugin itself.
P.S. I am using CakePHP 2.4.1
Use $tablePrefix in your plugin model:
<?php
// Plugin/Example/Model/ExampleAppModel.php
App::uses('AppModel', 'Model');
class ExampleAppModel extends AppModel {
/**
* Table prefix
*/
public $tablePrefix = 'example_';
}
Then, all your models in Example plugin will use example_ prefix
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With