Hello,
do you have any way (or it’s possible) to add some custom prefix in table names, for example, I am at work on a user module, I have an account table. and I want to model or repository automatically add this prefix. for example
p18g_account or p18g_user_account,
its good if it can be added on config files
Edit: p18g is random prefix for add to all of the tables for more security
Thank you very much, But by this config, I have to set table_prefix for each table manually, I looking for a method to add this setting just in one area, does laminas-db have this option?
I am afraid it does not by default - however you could introduce a subclass of AbstractTableGateway and handle the table prefix there. you will still need to change any references on the original TableGateway-class to your own implementation.
Sample code from the docs (I don’t know if you would need the GlobalAdapterFeature, but if I were to guess, you don’t.)
use Laminas\Db\TableGateway\Feature;
class MyTableGateway extends AbstractTableGateway
{
public function __construct($prefix)
{
$this->table = $prefix.'_my_table';
$this->initialize();
}
}
$prefix could come from a TableGatewayFactory where you get it from the configuration as mentioned in previous posts.
They asked for a option to set the prefix in one area - if setting a TableIdentifier would do that too, that’s cool and the idea with extending is to be entirely blamed on me thinking too big lol
Thank you, that means much to me coming from you
To be honest and after some thought, I like my first approach more too.
Ultimately, the choice is up to Voltan, though.
Regardless of the state of laminas-db, it is still widely used and installed in skeleton applications - which means that we do need to make do with laminas-db until someone comes up with a migration path to doctrine
You can always use something other than laminas-db because it is not a required dependency for laminas-mvc or Mezzio.
I have not used the component myself for several years.