[MODx] 7. MIGX DB

MODx provides a really unfriendly way to work with xPDO class. What I means is you need to define XML schma, mysql table and run the script to generate other stuff (model and controller), which is really suck...

Luckly, MIGX DB could help you finish those task easily.

1. Install MIGX package.

2. On the topp menu, find "Extras" => "MIGX".

3. Enter into the MIGX Management,

go to "XML Schema" tab, define the schea here.

<?xml version="1.0" encoding="UTF-8"?>
<model package="storefinder" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" phpdoc-package="storefinder" phpdoc-subpackage="model" version="1.1">
  <object class="sfStore" table="sfinder_stores" extends="xPDOSimpleObject">
    <field key="name" dbtype="varchar" precision="100" phptype="string" null="false" default="" index="index" />
    <field key="address" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
    <field key="city" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
    <field key="state" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
    <field key="zip" dbtype="varchar" precision="10" phptype="string" null="false" default="0" index="index" />
    <field key="country" dbtype="varchar" precision="20" phptype="string" null="false" default="" />
    <field key="phone" dbtype="varchar" precision="20" phptype="string" null="false" default="" />
    <field key="fax" dbtype="varchar" precision="20" phptype="string" null="false" default="" />
    <field key="active" dbtype="int" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
    <alias key="postalcode" field="zip" />
    <index alias="name" name="name" primary="false" unique="false" type="BTREE">
        <column key="name" length="" collation="A" null="false" />
    </index>
    <index alias="zip" name="zip" primary="false" unique="false" type="BTREE">
        <column key="zip" length="" collation="A" null="false" />
    </index>
  </object>
  <object class="sfOwner" table="sfinder_owners" extends="xPDOSimpleObject">
    <field key="name" dbtype="varchar" precision="100" phptype="string" null="false" default="" index="index" />
    <field key="email" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
    <index alias="name" name="name" primary="false" unique="false" type="BTREE">
        <column key="name" length="" collation="A" null="false" />
    </index>
  </object>
  <object class="sfStoreOwner" table="sfinder_store_owners" extends="xPDOSimpleObject">
    <field key="store" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" index="index" />
    <field key="owner" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" index="index" />
    <index alias="store" name="store" primary="false" unique="false" type="BTREE">
        <column key="store" length="" collation="A" null="false" />
    </index>
    <index alias="owner" name="owner" primary="false" unique="false" type="BTREE">
        <column key="owner" length="" collation="A" null="false" />
    </index>
  </object>
</model>

I just copy the xml from here.

4. Click "Save Schema".

5. Go to "Parse schema" tab to click "Parse schema" button, this will generate model and controller class.php.

6. Go to Create Table tab, click "Create Table" button. This will create mysql table for your according to your xml.

7. Just mock some dump data into the table and test it out. For example, we add two rows of data into modx_sfinder_stores table.

create a snippet called "store".

<?php
$path = MODX_CORE_PATH . ‘components/storefinder/‘;
$result = $modx->addPackage(‘storefinder‘,$path .
    ‘model/‘,‘modx_‘);

$storefinder = $modx->newObject(‘sfStore‘);
$storefinder->set(‘name‘, "XOPO");
$storefinder->set(‘address‘, "Somewhere in the world");
$storefinder->set(‘city‘, "Helsinki");
$storefinder->set(‘state‘, "north Karera");
$storefinder->set(‘zip‘, "88888");
$storefinder->set(‘country‘, "Finland");
$storefinder->set(‘phone‘, "987654");
$storefinder->set(‘fax‘, "0332");
$storefinder->set(‘active‘, "0");
$storefinder->save();

8. Run the snippet should be able to add data into the database, then we can view the data.

<?php
$path = MODX_CORE_PATH . ‘components/storefinder/‘;
$result = $modx->addPackage(‘storefinder‘,$path .
    ‘model/‘,‘modx_‘);

$result= $modx->getCollection(‘sfStore‘);
$stores = array();

foreach($result as $res){

   echo $res->get(‘name‘);
   echo $res->get(‘address‘);
}
时间: 2024-12-16 10:39:33

[MODx] 7. MIGX DB的相关文章

[MODx] Build a CMP (Custom manager page) using MIGX in MODX 2.3 -- 1

BIG FUCK for MODx MODx document is not that good  ...  at least in my opint of view. I spend hours to search martirals to find out how to build a CMP by using MIGX in MODX 2.3. The officail doument are written for 2.2, but since 2.3, it changed a lot

[MODx] Build a CMP (Custom manager page) using MIGX in MODX 2.3 -- 2

We are not finishing yet... 1. Under MIGX Management, we need to add some "Actionbuttons" 2. Also some "contextmenus": 3. Add some 'columns' to the forms, the fields of the columns should match the fields in database (or xml schema): F

Mac&#160;下locate命令使用问题WARNING: The locate database (/var/db/locate.database) does not exist.

想在Mac下使用locate时,提醒数据库没创建: WARNING: The locate database (/var/db/locate.database) does not exist. To create the database, run the following command: sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist Please be aware that the d

centos 6 oracle 11G DB install

因业务迁移,需重新部署oracle DB,此文仅作部署记录,部署文档主要参考官方文档http://docs.oracle.com/cd/E11882_01/install.112/e47689/toc.htm 概要: 主机:OpenStack 云主机 系统:Completing a Minimal Linux centos 6.8 x86_64 DB:Oracle Database 11g Release 2(11.2) 内存:2Gb 硬盘:/dev/vda 20Gb /dev/vdb 30Gb

RDBMS DBMS MS DB

RDBMS系统是在E.F.Codd博士发表的论文<大规模共享数据银行的关系型模型>(Communications of the ACM杂志1970年6月刊)基础上设计出来的.它通过数据.关系和对数据的约束三者组成的数据模型来存放和管理数据.三十多年来,RDBMS获得了长足 的发展,目前许多企业的在线交易处理系统.内部财务系统.客户管理系统等大多采用了RDBMS.太字节级关系型数据库在大型企业集团中已是司空见惯.目前 业界普遍使用的关系型数据库管理系统产品有IBM DB2通用数据库.Oracle

关于jFinal Db.query与Db.find 的理解

1.Db.query,返回的是List<Model>类型,实际上返回的却是 Model 的数组: 2.Db.find,返回List<Reocrd>类型,实际上是recrod的 list: 3.所以相关Mode中的dao只有find,没有query,只有Db类中既有find也有query,可以灵活运用

【DB】范式

在我的上一篇博客<[DB]函数依赖>中,主要讲解了什么是函数依赖以及局部和传递依赖(FD).在没有FD时,关系中是不可能有数据冗余,但当FD存在时,关系中就有可能存在数据冗余.如何消除呢?答案是模式分解.那么分解成什么样子,如何来衡量关系模式的好与坏?答案是范式(NF)! NF的种类与FD有着直接的联系,基于FD的范式有1NF.2NF.3NF.BCNF.4NF等多种.下面就分别介绍一下! 1NF 关系模式R的每个关系r,其属性为单值属性 2NF 消除局部依赖 3NF 消除传递依赖 BCNF 在

[转]Oracle DB 查看预警日志

"Database(数据库)"主页>"Related Links相关链接)"区域> "Alert Log Content (预警日志内容)" 查看预警日志 每个数据库都有一个alert_<sid >.log文件.此文件位于数据库所在的服务器中,如果设置了$ORACLE_BASE,则此文件默认存储在$ORACLE_BASE/diag/rdbms/<db_name>/<SID>/trace中. 数据库预

DB处理大量数据处理日志报错问题

因为当插入.更新或删除大批量数据的时候,有时候会出现事务日志满的问题,所以解决步骤 1.连接到当前数据库 db2 connect to uppdb 2.查看数据库配置文件 db2 get db cfg for uppdb 此命令可以查看数据库相关配置,包括字符集.日志文件大小等 查看当前数据库的日志文件大小(LOGFILSIZ),主日志数(LOGPRIMARY),辅日志数(LOGSECOND) 一般默认设置:logfilsiz:4k,logprimary:10,logsecond:2 3.修改日