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. 各种html5 的 polyfill

    https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-browser-Polyfills 配合 Modernizr

  2. Unity3D如何获取对象和子对象

    在Unity3d中获取游戏对象有三种方法: 一:获取对象 1.通过对象名称获取:objCube=GameObject.Find("Cube"); private var objCu ...

  3. mysql_insert_id 为什么会返回空值

    如果同时打开了一个以上的数据库资源,如果其中一个资源,没有使用insert语句或没有auto_increment类型的数据,或返回结果恰好为空值时,会导致mysql_insert_id()返回空值. ...

  4. 学习面试题Day07

    1.打印出100以内的素数 该编程题的思路大致如下: (1)完成一个判断某整数是否为素数的方法: (2)循环1--100: (3)每循环一次就判断一次,返回true则打印:package com.ex ...

  5. ejabberd中的http反向推送

    http的反向推送通常使用"长轮询"或"长连接"的方式. 所谓"长轮询"是指客户端发送请求给服务器,服务器发现没有数据需要发送给客户端. h ...

  6. Win32汇编环境配置

    放假了,发现自己知识面窄,趁有时间就打算折腾下Win32汇编.其实在学校也上过汇编课,是基于dos的.那时老师不务正业,老跟我们讲政治经济文化,唯独不怎么讲课;再加上自己的问题,导致了dos汇编学得好 ...

  7. [转] Symbol对象

    GIS中的离散实体有三种:点.线.面,在ArcEngine中用三种符号对应表示,分别是:MarkSymbol.LineSymbol和FillSymbol.此外还有TextSymbol用于文字标注,3D ...

  8. LoadRunner常见问题整理(转)

    首先要感谢群友的无私分享,才能得到这篇好的学习资料,整理得太好了,所以收藏保存,方便以后学习. 一:LoadRunner常见问题整理 1.LR 脚本为空的解决方法: 1.去掉ie设置中的第三方支持取消 ...

  9. VBScript: 正则表达式(RegExp对象)

    RegExp对象是VBScript中用于提供简单地正则表达式支持的对象.VBScript中所有和正则表达式有关的属性和方法都有这个对象有关联. 一.RegExp对象的属性和方法(三个属性,三个方法) ...

  10. uva 11178

    题意:根据A,B,C三点的位置确定D,E,F三个点的位置. 贴模板 #include<cstdio> #include<cmath> #include<cstring&g ...