几乎完成了从 1.3.14 到 2.0.5 的 CakePHP 迁移(在一个我没有编写的非常大的项目上)剩下的问题之一是 XML Helper 的弃用。
2.0.5 中的新 XML 类在我以前工作的地方失败了。迁移指南指出“现在这个类不再操作数据,它是 SimpleXMLElement 的包装器” http://book.cakephp.org/2.0/en/appendices/2-0-migration-guide.html#xml
以前我使用的是:
file_put_contents($xml_file, $this->Xml->serialize($quote, array('encoding' => 'UTF-8')));
我尝试将上述内容替换为:
$xml = Xml::build($quote, array(
'encoding' => 'UTF-8',
'format' => 'attributes'));
然而,我得到的只是一个异常'XmlException',带有消息'无效输入'。我在下面包含了一个示例数组。基本上,新的 XML 类不喜欢数组输入。应用程序的多个部分都生成复杂的 XML,并且存在相同的问题。
有没有人遇到过这个问题?我将永远调试它。
我想一个潜在的解决方法是复制旧的 Xml.php 和帮助程序,并可能制作一个插件,但如果可能的话,我更愿意让这一切正常工作。
样本数组:
Array
(
[Quote] => Array
(
[id] => 1
[quote_template_id] => 1
[project_id] => 1
[quote_status_id] => 1
[client_id] => 1
[date_added] => 2011-05-11
[is_archived] => 0
[comment] => Revision 2.
)
[Project] => Array
(
[id] => 1
[project_status_id] => 2
[user_id] => 5
[salesperson_id] => 5
[site_id] => 1
[name] => Test Project
[description] =>
[is_archived] => 0
[date_added] => 2011-05-11
[expected_start] => 2011-05-11
[Actual_start] =>
[expected_finish] => 2011-05-11
[actual_finish] =>
[special_clearance] => 1
[ProjectStatus] => Array
(
[id] => 2
[name] => Tendering
)
[User] => Array
(
[id] => 5
[user_group_id] => 5
[username] => operations
[password] => 7de1e823411aec881a96475e614d6286b944e92b
[first_name] => Operations
[last_name] => Person
[contact_phone] => 0400 000 000
[contact_number] => 0400 000 000
[emerg_contact_name] => 123
[emerg_contact_phone] => 0400 000 000
[is_active] => 1
[is_reset_required] => 0
[address] => 123
[state] => VIC
[suburb] => 123
[postcode] => 3000
[full_name] => Operations Person
)
[Site] => Array
(
[id] => 1
[site_type_id] => 1
[zone_id] => 1
[name] => Highpoint Test Site
[address] => 200 Rosamond Road
[suburb] => Maribyrnong
[postcode] => 3032
[state] => VIC
[melway_ref] => -
[date_added] => 2011-02-25 11:19:00
[comment] => This is just a test site
[is_active] => 1
)
[Salesperson] => Array
(
[id] => 5
[user_group_id] => 5
[username] => operations
[password] => 7de1e823411aec881a96475e614d6286b944e92b
[first_name] => Operations
[last_name] => Person
[contact_phone] => 0400 000 000
[contact_number] => 0400 000 000
[emerg_contact_name] => 123
[emerg_contact_phone] => 0400 000 000
[is_active] => 1
[is_reset_required] => 0
[address] => 123
[state] => VIC
[suburb] => 123
[postcode] => 3000
[full_name] => Operations Person
)
[ProjectStatusChange] => Array
(
[0] => Array
(
[id] => 1
[project_id] => 1
[project_status_id] => 1
[created] => 2011-05-11 17:27:14
)
[1] => Array
(
[id] => 2
[project_id] => 1
[project_status_id] => 2
[created] => 2011-05-11 17:27:23
)
)
[EquipType] => Array
(
[0] => Array
(
[id] => 2
[category_id] => 3
[name] => 1-3.5 Tonne Excavator
[description] => this is just a test excavator
[is_usable_for_cartage] => 0
[EquipTypesProject] => Array
(
[id] => 1
[equip_type_id] => 2
[project_id] => 1
)
)
[1] => Array
(
[id] => 4
[category_id] => 3
[name] => Float to Site
[description] =>
[is_usable_for_cartage] => 0
[EquipTypesProject] => Array
(
[id] => 2
[equip_type_id] => 4
[project_id] => 1
)
)
)
[MaterialType] => Array
(
[0] => Array
(
[id] => 6
[code] => IB
[name] => Clean Brick
[is_active] => 1
[MaterialTypesProject] => Array
(
[id] => 4
[material_type_id] => 6
[project_id] => 1
[is_importable] => 0
[is_exportable] => 0
)
)
[1] => Array
(
[id] => 28
[code] => C
[name] => General Clay
[is_active] => 1
[MaterialTypesProject] => Array
(
[id] => 5
[material_type_id] => 28
[project_id] => 1
[is_importable] => 0
[is_exportable] => 0
)
)
[2] => Array
(
[id] => 38
[code] => S
[name] => Sand
[is_active] => 1
[MaterialTypesProject] => Array
(
[id] => 6
[material_type_id] => 38
[project_id] => 1
[is_importable] => 0
[is_exportable] => 0
)
)
)
)
[QuoteStatus] => Array
(
[id] => 1
[name] => Tendering
[Quote] => Array
(
[0] => Array
(
[id] => 1
[quote_template_id] => 1
[project_id] => 1
[quote_status_id] => 1
[client_id] => 1
[date_added] => 2011-05-11
[is_archived] => 0
)
)
)
[Revision] => Array
(
[0] => Array
(
[Revision] => Array
(
[id] => 3
[quote_id] => 1
[name] => Q-1-3
[comment] => Revision 2.
[user_id] => 5
[revision_time] => 2011-05-11 17:32:55
[quote_status_id] => 1
)
)
)
[QuoteContact] => Array
(
[0] => Array
(
[id] => 1
[contact_id] => 18
[quote_id] => 1
[Contact] => Array
(
[SEQNO] => 18
[SALUTATION] => Mr
[FIRSTNAME] => Bob
[LASTNAME] => Test
[TITLE] => Sales
[MOBILE] =>
[DIRECTPHONE] => 612-9999 9999
[DIRECTFAX] => 612-9999 9999
[HOMEPHONE] =>
[EMAIL] => asdf@asdf.com.au
[NOTES] =>
[ADDRESS1] => PO BOX 1111
[ADDRESS2] => PENRITH
[ADDRESS3] => NSW AUSTRALIA
[ADDRESS4] =>
[DELADDR5] =>
[DELADDR6] =>
[POST_CODE] =>
[DELADDR1] => 1 CLARKE ST
[DELADDR2] => PENRITH
[DELADDR3] => SYDNEY
[DELADDR4] => AUSTRALIA
[ISACTIVE] => Y
[ADVERTSOURCE] => 0
[SALESNO] => 1
[FULLNAME] => Bob Chancellor
[COMPANY_ACCNO] =>
[COMPANY_ACCTYPE] =>
[MSN_ID] =>
[YAHOO_ID] =>
[SKYPE_ID] =>
[ADDRESS5] =>
[LAST_UPDATED] => 2010-05-19 16:39:42
[id] => 18
[name] => Bob Test
[email] => asdf@asdf.com.au
)
[Quote] => Array
(
[id] => 1
[quote_template_id] => 1
[project_id] => 1
[quote_status_id] => 1
[client_id] => 1
[date_added] => 2011-05-11
[is_archived] => 0
)
)
)
)