如何向magento数据库添加新表

发布于 2024-10-11 17:14:19 字数 132 浏览 3 评论 0原文

我正在使用 magento 1.4.2.0,我需要向我的 magento 数据库添加一个新表,它适用于我的一些自定义 cms 页面,我需要将数据添加到数据库并需要获取该数据并将其显示在 cms 页面中.请逐步解释我,因为我对 magento 很陌生。

I am using magento 1.4.2.0 and i need to add a new table to my magento database,It is for some of my custom cms pages where i need to add data to database and need to fetch that data and show it in the cms pages.Please explain me step by step as i am very new to magento.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

独守阴晴ぅ圆缺 2024-10-18 17:14:19

您必须在模块中使用安装文件:查看 Alan Storm 的综合帖子

you have to use a setup file in your module: check out Alan Storm's comprehensive post

别把无礼当个性 2024-10-18 17:14:19

使用magento模块创建表在sql文件夹mysql4-install-1.0.0.php文件中写入以下代码。

$installer = $this;
$table = $installer->getConnection()->newTable($installer->getTable(''))
->addColumn('news_id',Varien_Db_Dbl_Table::INTEGER_TYPE,null,array('unsigned'=>true,'identity'=>true,'nullable'=>false,'primary'=>true),'Entity Id')
->addColumn('title',Varien_Db_Dbl_Table::TYPE_TEXT,255,array('nullable'=>true),'Title')
->addColumn('author',Varien_Db_Dbl_Table::TYPE_TEXT,63,array('nullable'=>true,'default'=>'null'),'Author')
->addColumn('content',Varien_Db_Dbl_Table::TYPE_TEXT,'2M',array('nullable'=>true,'default'=>'null'),'Content')
->addColumn('image',Varien_Db_Dbl_Table::TYPE_TEXT,null,array('nullable'=>true,'default'=>'null'),'News Image Media Path')
->addColumn('publised_at',Varien_Db_Dbl_Table::TYPE_DATE,null,array('nullable'=>true,'default'=>'null'),'Published Date')
->addColumn('created_at',Varien_Db_Dbl_Table::TYPE_TIMESTAMP,null,array('nullable'=>true,'default'=>'null'),'Creation Time')
->addIndex($installer->getIdxName($installer->getTable(''),array('publised_at'),Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX),array('publised_at'),array('type'=>Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX))->SetComment('News Item');
$installer->getConnection->createTable($table);

Create table using magento module write following code in sql folder mysql4-install-1.0.0.php file.

$installer = $this;
$table = $installer->getConnection()->newTable($installer->getTable(''))
->addColumn('news_id',Varien_Db_Dbl_Table::INTEGER_TYPE,null,array('unsigned'=>true,'identity'=>true,'nullable'=>false,'primary'=>true),'Entity Id')
->addColumn('title',Varien_Db_Dbl_Table::TYPE_TEXT,255,array('nullable'=>true),'Title')
->addColumn('author',Varien_Db_Dbl_Table::TYPE_TEXT,63,array('nullable'=>true,'default'=>'null'),'Author')
->addColumn('content',Varien_Db_Dbl_Table::TYPE_TEXT,'2M',array('nullable'=>true,'default'=>'null'),'Content')
->addColumn('image',Varien_Db_Dbl_Table::TYPE_TEXT,null,array('nullable'=>true,'default'=>'null'),'News Image Media Path')
->addColumn('publised_at',Varien_Db_Dbl_Table::TYPE_DATE,null,array('nullable'=>true,'default'=>'null'),'Published Date')
->addColumn('created_at',Varien_Db_Dbl_Table::TYPE_TIMESTAMP,null,array('nullable'=>true,'default'=>'null'),'Creation Time')
->addIndex($installer->getIdxName($installer->getTable(''),array('publised_at'),Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX),array('publised_at'),array('type'=>Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX))->SetComment('News Item');
$installer->getConnection->createTable($table);
吃不饱 2024-10-18 17:14:19
class InstallSchema implements \Magento\Framework\Setup\InstallSchemaInterface
{

    public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        $setup->startSetup();
        $table = $setup->getConnection()
        ->newTable($setup->getTable('magento_pincode_pincode'))
        ->addColumn(
                    'pincode_id',
                    \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                    null,
                    [
                        'identity' => true,
                        'nullable' => false,
                        'primary'  => true,
                        'unsigned' => true
                    ],
                    'ID'
                )->addColumn(
                    'pincode',
                    \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                    null,
                    ['nullable' => false],
                    'Pincode'
                )->addColumn(
                    'status',
                    \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                    255,
                    ['nullable' => false],
                    'Status'
                )->addColumn(
                    'created_at',
                    \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
                    null,
                    ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT],
                    'Created At'
                )->addColumn(
                    'updated_at',
                    \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
                    null,
                    ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE],
                    'Updated At');
            $setup->getConnection()->createTable($table);

            $setup->endSetup();

    }
}
class InstallSchema implements \Magento\Framework\Setup\InstallSchemaInterface
{

    public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        $setup->startSetup();
        $table = $setup->getConnection()
        ->newTable($setup->getTable('magento_pincode_pincode'))
        ->addColumn(
                    'pincode_id',
                    \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                    null,
                    [
                        'identity' => true,
                        'nullable' => false,
                        'primary'  => true,
                        'unsigned' => true
                    ],
                    'ID'
                )->addColumn(
                    'pincode',
                    \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                    null,
                    ['nullable' => false],
                    'Pincode'
                )->addColumn(
                    'status',
                    \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                    255,
                    ['nullable' => false],
                    'Status'
                )->addColumn(
                    'created_at',
                    \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
                    null,
                    ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT],
                    'Created At'
                )->addColumn(
                    'updated_at',
                    \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
                    null,
                    ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE],
                    'Updated At');
            $setup->getConnection()->createTable($table);

            $setup->endSetup();

    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文