[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, 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的更多相关文章
- [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 ...
- [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" ...
- 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. ...
- VS15 preview 5打开文件夹自动生成slnx.VC.db SQLite库疑惑?求解答
用VS15 preview 5打开文件夹(详情查看博客http://www.cnblogs.com/zsy/p/5962242.html中配置),文件夹下多一个slnx.VC.db文件,如下图: 本文 ...
- ODBC、OLE DB、 ADO的区别
转自:http://blog.csdn.net/yinjingjing198808/article/details/7665577 一.ODBC ODBC的由来 1992年Microsoft和Syba ...
- 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 ...
- SSRS ----环境配置,没有 ReportServer DB 怎么办?
今天项目进入报表开发阶段,按照习惯,打开报表管理器,发现提示下面的错误: 错误:报表服务器无法打开与报表服务器数据库的连接.所有请求和处理都要求与数据库建立连接. 这是怎么回事儿呢,经过排查,发现数据 ...
- mongo DB for C#
(1)Download the MongoDB C#驱动. http://www.nuget.org/packages/mongocsharpdriver/. (2) Add Reference to ...
- 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 ...
随机推荐
- 12月上旬poj其他题
poj3170 1,4两遍bfs: poj3171 改一改poj2376即可 poj3172 dfs+剪枝 其实增长速度很快,n<=40,题目吓你的: poj3661 比较经典的dp:设f[i, ...
- POJ 1269 (直线相交) Intersecting Lines
水题,以前总结的模板还是很好用的. #include <cstdio> #include <cmath> using namespace std; ; int dcmp(dou ...
- HAOI2006受欢迎的牛
求出强联通分量之后判断出度为0的点有几个,有1个就输出这个分量的点的数目,否则输出0: var i,j,n,m,x,y,ans1,ans2,t,cnt,top:longint; head,next,g ...
- python auto send email
/*************************************************************************** * python auto send emai ...
- (转) mysql数据库引擎:MyISAM和InnoDB(性能优化)
转自 http://yuwensan126.iteye.com/blog/1138022 Mysql 数据库中,最常用的两种引擎是innordb和myisam.Innordb的功能要比myiasm强大 ...
- span文字在左背景图片在右
<html><head><meta http-equiv="Content-Type" content="text/html; charse ...
- Ext入门学习系列(二)弹出窗体
第二章 弹出窗体 上节学习了Ext的环境搭建和最基本的一个操作——弹出对话框,作为一个引子,本节讲述如何弹出一个新窗体,从实例讲解Ext的基本运行原理. 一.Ext的窗体长什么样? 先来看看几个效果, ...
- Linux 多线程编程--线程退出
今天分析项目中进程中虚存一直增长问题,运行10个小时虚存涨到121G ,RSS占用为16G 非常恐怖. Valgrind测试无内存泄漏. 内存32G 64bit系统信息如下: Linux线程使用方式是 ...
- 【转】C/C++除法实现方式及负数取模详解
原帖:http://blog.csdn.net/sonydvd123/article/details/8245057 一.下面的题目你能全做对吗? 1.7/4=? 2.7/(-4)=? 3.7%4=? ...
- 输入一个整数n,求从1到n这n个整数的十进制表示中1出现的次数
题目:输入一个整数n,求从1到n这n个整数的十进制表示中1出现的次数.例如输入12,从1到12这些整数中包含1 的数字有1,10,11和12,1一共出现了5次. 分析:首先最先想到的是遍历从1到n的每 ...