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, fill in the package and prefix information:

Then click "Create Package" button.

4. 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.

5. Click "Save Schema".

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

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

8. 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();

9. 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');
}

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

  1. [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 t ...

  2. [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" ...

  3. Linux平台 Oracle 10gR2(10.2.0.5)RAC安装 Part3:db安装和升级

    Linux平台 Oracle 10gR2(10.2.0.5)RAC安装 Part3:db安装和升级 环境:OEL 5.7 + Oracle 10.2.0.5 RAC 5.安装Database软件 5. ...

  4. VS15 preview 5打开文件夹自动生成slnx.VC.db SQLite库疑惑?求解答

    用VS15 preview 5打开文件夹(详情查看博客http://www.cnblogs.com/zsy/p/5962242.html中配置),文件夹下多一个slnx.VC.db文件,如下图: 本文 ...

  5. ODBC、OLE DB、 ADO的区别

    转自:http://blog.csdn.net/yinjingjing198808/article/details/7665577 一.ODBC ODBC的由来 1992年Microsoft和Syba ...

  6. Linux平台 Oracle 11gR2 RAC安装Part3:DB安装

    四.DB(Database)安装 4.1 解压DB的安装包 4.2 DB软件安装 4.3 ASMCA创建磁盘组 4.4 DBCA建库 4.5 验证crsctl的状态 Linux平台 Oracle 11 ...

  7. SSRS ----环境配置,没有 ReportServer DB 怎么办?

    今天项目进入报表开发阶段,按照习惯,打开报表管理器,发现提示下面的错误: 错误:报表服务器无法打开与报表服务器数据库的连接.所有请求和处理都要求与数据库建立连接. 这是怎么回事儿呢,经过排查,发现数据 ...

  8. mongo DB for C#

    (1)Download the MongoDB C#驱动. http://www.nuget.org/packages/mongocsharpdriver/. (2) Add Reference to ...

  9. jBPM4.4 no jBPM DB schema: no JBPM4_EXECUTION table. Run the create.jbpm.schema target first in the install tool.

    jBPM4.4 no jBPM DB schema: no JBPM4_EXECUTION table. Run the create.jbpm.schema target first in the ...

随机推荐

  1. vfp 操作excel

    VFP全面控制EXCEL 收藏 VFP和Excel都可以用来进行处理数据库表格,如果巧妙地将二者的优点结合起来,将会大大方便我们的工作.比如我们可以利用VFP进行处理数据,而利用Excel的预览打印功 ...

  2. 百度地图API的调用

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head ...

  3. 8.21 usaco

    summary:6 bzoj1692://后缀数组就行了O(nlogn)c[30]会RE...注意!!! #include<cstdio> #include<cstring> ...

  4. (3)java棧

    java棧和函数调用的关系图 [名词解释]--->java棧是一块线程的私有空间--->java的棧是先进后出的数据结构.函数返回,则该函数的棧帧被弹出.--->一个函数对应一个棧帧 ...

  5. linux中的设备名称和设备号

    看赵炯博士的<linux 0.11 源代码注释>已经两三周了,从今天起开始将一些个人总结和感悟分小标题写出来,聊作记忆以供后来查看.在linux0.11源码的 /linux/boot/bo ...

  6. ZOJ 2283 Challenge of Wisdom

    题意:在一个n * m的地图里,有p个宝藏,每次只能向横纵坐标增加的方向走,问最少走几次能把宝藏都拿走. 解法:按横坐标排序,纵坐标的一个不下降子序列就是一条合法路径,要求多少条不下降子序列可以覆盖所 ...

  7. Parallel for-each loops in .NET C# z

    An IEnumerable object An Action of T which is used to process each item in the list List<string&g ...

  8. delphi通过OLE对word进行单元格合并操作

    uses comobj, word2000procedure TForm1.Button2Click(Sender: TObject);var WordApp, WordDoc,table: OleV ...

  9. POJ 2486-Apple Tree(树状背包)

    题意 n个节点的树,每个节点都有价值,求在树上最多走k步获得的最大价值(从1开始走,节点的价值只能获取一次) 分析: 开始以为是最基础的树形背包,但后来发现,不能只走子树,有可能还回到根节点,dp[i ...

  10. MFC对话框

    创建对话框步骤: 第一,创建对话框资源,主要包括创建新的对话框模板.设置对话框属性和为对话框添加各种控件: 第二,生成对话框类,主要包括新建对话框类.添加控件变量和控件的消息处理函数等. 创建对话框类 ...