For my custom module I create a database table with the magento sql setups script. The problem is that if the magento installation has a prefix on the database it doesn't add the prefix. So the table is created but without the needed prefix.
Anybody knows how I can add this to my script?
-
please add your script to the question.Marius– Marius2014年07月24日 09:23:07 +00:00Commented Jul 24, 2014 at 9:23
3 Answers 3
Use $this->getTable('yourmodule_table') in your sql script. The reference yourmodule_table should match what you have defined as a table in your config.xml.
You tried this?
$prefix = Mage::getConfig()->getTablePrefix();
echo $prefix;
While creating table in script file add $prefix to the table name.
Hope this will help you:)
suppose if your module is yourmodule and the table name is yourtablename, so in the app/code/local/yourcompmay/yourmodule/etc/config.xml file of this module, the resource entity tag will look like:
<entities>
<yourtable1> <!-- this is the reference of the table -->
<table>yourtablename</table> <!--enter the actual table name within these table tags-->
</yourtable1>
</entities>
now you can call the table by reference by using the following code in setup files:
$this->getTable('module / table reference');
if I use above exampled values, it will become $this->getTable('yourmodule/yourtable1');, this will return the table name (with prefix if any).