magento2框架MVVC開發入門(四)创建 Magento 2 CRUD 模型

        数据管理CRUD必须创建Model,Resource Model,Resource Model Conllection来管理表中的数据。

        为“待办事项”项目创建一个模型。 我们希望这个模型有两个主要字段——待办事项的文本和完成日期字段。首先新建一个magento2模块ToDoCrud(待办事项)

一、新建表或属性

待办事项表主要需要包含以下字段:

item_id
content
creation_at
update_at
is_active

 在ToDoCrud/etc目录下新建db_schema.xml(相当于数据库表映射文件),内容如下:

<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
    <table name="bcn_todo_list" resource="default" engine="innodb" comment="blog post list">
        <column xsi:type="int" name="item_id" unsigned="true" nullable="false" identity="true" comment="ID"/>
        <column xsi:type="text" name="content" nullable="true" comment="content"/>
        <column xsi:type="timestamp" name="created_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP" comment="Creation Time"/>
        <column xsi:type="timestamp" name="updated_at" on_update="true" nullable="false" default="CURRENT_TIMESTAMP" comment="Update Time"/>
        <column xsi:
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值