【问题标题】:Disable table prefix Magento禁用表前缀 Magento
【发布时间】:2013-10-13 23:30:35
【问题描述】:

我开发了一个模块来从 Magento 访问外部数据库,当我在干净的 Magento 安装上测试模块时它工作正常,但是当我在使用表前缀的干净 Magento 安装上测试它时它失败了,因为它添加模块上使用的外部表名称的前缀。

有没有办法禁用模块上使用的所有外部表的表前缀?

我希望该模块适用于带有或不带有表前缀的安装。我已经尝试添加:

<table_prefix><![CDATA[]]></table_prefix>

在我的模块的config.xml部分下没有任何运气。

有什么想法吗?

【问题讨论】:

    标签: php magento magento-1.7


    【解决方案1】:

    Ox3,一种选择是为您自己的模块创建连接,例如:

    <?xml version="1.0"?>
    <config>
        <modules>
            <Vendor_Mymodule>
                <version>0.1.0</version>
            </Vendor_Mymodule>
        </modules>
        <global>
            <models>
                <mymodule>
                    <class>Vendor_Mymodule_Model</class>
                </mymodule>
            </models>
            <resources>
                <mymodule_write>
                    <connection>
                        <use>mymodule_setup</use>
                    </connection>
                </mymodule_write>
                <mymodule_read>
                    <connection>
                        <use>mymodule_setup</use>
                    </connection>
                </mymodule_read>
                <mymodule_setup>
                    <connection>
                        <host><![CDATA[localhost]]></host>
                        <username><![CDATA[username]]></username>
                        <password><![CDATA[password]]></password>
                        <dbname><![CDATA[db_name]]></dbname>
                        <model>mysql4</model>
                        <initStatements>SET NAMES utf8</initStatements>
                        <type>pdo_mysql</type>
                        <active>1</active>
                    </connection>
                </mymodule_setup>
            </resources>
        </global>
    </config> 
    

    然后你可以在你的代码中调用它:

     $new_conn = Mage::getSingleton('core/resource')->getConnection('mymodule_read');
    

    我希望它有所帮助。干杯!

    【讨论】:

    • 感谢您的回复,我已经为模块使用了单独的连接,问题是当我在模块。
    猜你喜欢
    • 1970-01-01
    • 2013-01-26
    • 2011-09-22
    • 2012-11-07
    • 2013-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多