[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 ...
随机推荐
- 大四实习准备5_android广播机制
2015-5-1 android 广播机制 5.1简介 分为标准广播(Normal broadcasts)(无先后顺序,几乎同时接收,不可截断)和有序广播(Ordered broadcasts)(有先 ...
- SCADA软件整体架构
SCADA软件整体框架如下所示: 1.免费版本可以支持的IO容量为2048点,无运行时间限制. 2.免费版本仅支持本地Runtime运行,CLServer服务器只能运行24小时. 3.免费版本支持的驱 ...
- 最受 Web 开发者欢迎的 NoSQL 和关系数据库
Web应用离不开数据库,目前市场上有种类繁多数据库可供开发者选择,例如SQL.NoSQL.键值.图谱数据库等等.关于不同数据库在开发者中的受欢迎程度也是仁者见仁智者见智,但是通过统计亚马逊这样的公共云 ...
- java高并发,如何解决,什么方式解决
之前我将高并发的解决方法误认为是线程或者是队列可以解决,因为高并发的时候是有很多用户在访问,导致出现系统数据不正确.丢失数据现象,所以想到 的是用队列解决,其实队列解决的方式也可以处理,比如我们在竞拍 ...
- 开源项目ets_cache分析
1 背景 当在程序中,有大量的数据需要读写,数据库的响应会延迟,甚至阻塞.缓存可以缓解对数据库访问的压力,而且在内存中数据的读写要比读写硬盘上的数据快. 2 目的 ets_cache是用erlang实 ...
- MySQL性能指标及计算方法
绝大多数MySQL性能指标可以通过以下两种方式获取: (1)mysqladmin 使用mysqladmin extended-status命令获得的MySQL的性能指标,默认为累计值.如果想了解当前状 ...
- 犯罪构成三层次记忆口诀 zt
犯罪构成三层次记忆口诀 2012-02-17 来源:为你辩护网 浏览次数:232 0 众所周知,犯罪构成“四要件”和犯罪构成“三层次”(“三阶层”)都是分析具体刑事案件的辅助性工具.犯罪构成四要件是指 ...
- 0、IOS8:Xcode6 playground
一.Playground介绍 Playground是Xcode6中自带的Swift代码开发环境.俗话说“功欲善其事,必先利其器”.以前在Xcode5中编写脚本代码,例如编写JS,其编写过程很痛苦,Xc ...
- HDU 5606 tree 并查集
tree 把每条边权是1的边断开,发现每个点离他最近的点个数就是他所在的连通块大小. 开一个并查集,每次读到边权是0的边就合并.最后Ansi=size[findset(i)],size表示每个并 ...
- bzoj 3198 [Sdoi2013]spring(容斥原理+Hash)
Description Input Output Sample Input 3 3 1 2 3 4 5 6 1 2 3 0 0 0 0 0 0 4 5 6 Sample Output 2 HINT [ ...