数据管理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: