本文整理汇总了PHP中Xml::child方法的典型用法代码示例。如果您正苦于以下问题:PHP Xml::child方法的具体用法?PHP Xml::child怎么用?PHP Xml::child使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Xml
的用法示例。
在下文中一共展示了Xml::child方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
function index()
{
$this->Plugin->recursive = 0;
$dbPluginList = $this->Plugin->find('list');
$dirPluginList = array();
if ($handle = opendir(ROOT . DS . 'app' . DS . 'plugins')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file != '.svn') {
$dirPluginList[] = $file;
}
}
closedir($handle);
}
$notInstalled = array_diff($dirPluginList, $dbPluginList);
$noFiles = array_diff($dbPluginList, $dirPluginList);
$this->Plugin->deleteAll(array('Plugin.id' => array_keys($noFiles)));
$plugins = $this->paginate();
App::import('Xml');
foreach ($plugins as &$plugin) {
$xml = new Xml(file_get_contents(ROOT . DS . 'app' . DS . 'plugins' . DS . $plugin['Plugin']['name'] . DS . 'meta.xml'));
$plugin['Plugin']['author'] = $xml->child('plugin')->child('author')->children[0]->value;
$plugin['Plugin']['email'] = $xml->child('plugin')->child('email')->children[0]->value;
$plugin['Plugin']['website'] = $xml->child('plugin')->child('website')->children[0]->value;
$plugin['Plugin']['description'] = $xml->child('plugin')->child('description')->children[0]->value;
}
$this->set('plugins', $plugins);
foreach ($notInstalled as $k => &$plugin) {
$plugin_name = $plugin;
$plugin = array();
$meta = ROOT . DS . 'app' . DS . 'plugins' . DS . $plugin_name . DS . 'meta.xml';
if (file_exists($meta)) {
$xml = new Xml(file_get_contents($meta));
$plugin['Plugin']['name'] = $plugin_name;
$plugin['Plugin']['author'] = $xml->child('plugin')->child('author')->children[0]->value;
$plugin['Plugin']['email'] = $xml->child('plugin')->child('email')->children[0]->value;
$plugin['Plugin']['website'] = $xml->child('plugin')->child('website')->children[0]->value;
$plugin['Plugin']['description'] = $xml->child('plugin')->child('description')->children[0]->value;
} else {
unset($notInstalled[$k]);
}
}
$this->set('notInstalled', $notInstalled);
}
示例2: testToArray
/**
* testToArray method
*
* @access public
* @return void
*/
function testToArray()
{
App::import('Set');
$string = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rss version="2.0">
<channel>
<title>Cake PHP Google Group</title>
<link>http://groups.google.com/group/cake-php</link>
<description>Search this group before posting anything. There are over 20,000 posts and it&#39;s very likely your question was answered before. Visit the IRC channel #cakephp at irc.freenode.net for live chat with users and developers of Cake. If you post, tell us the version of Cake, PHP, and database.</description>
<language>en</language>
<item>
<title>constructng result array when using findall</title>
<link>http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</link>
<description>i'm using cakephp to construct a logical data model array that will be <br> passed to a flex app. I have the following model association: <br> ServiceDay-&gt;(hasMany)ServiceTi me-&gt;(hasMany)ServiceTimePrice. So what <br> the current output from my findall is something like this example: <br> <p>Array( <br> [0] =&gt; Array(</description>
<guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</guid>
<author>bmil...@gmail.com(bpscrugs)</author>
<pubDate>Fri, 28 Dec 2007 00:44:14 UT</pubDate>
</item>
<item>
<title>Re: share views between actions?</title>
<link>http://groups.google.com/group/cake-php/msg/8b350d898707dad8</link>
<description>Then perhaps you might do us all a favour and refrain from replying to <br> things you do not understand. That goes especially for asinine comments. <br> Indeed. <br> To sum up: <br> No comment. <br> In my day, a simple &quot;RTFM&quot; would suffice. I'll keep in mind to ignore any <br> further responses from you. <br> You (and I) were referring to the *online documentation*, not other</description>
<guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/8b350d898707dad8</guid>
<author>subtropolis.z...@gmail.com(subtropolis zijn)</author>
<pubDate>Fri, 28 Dec 2007 00:45:01 UT</pubDate>
</item>
</channel>
</rss>';
$xml = new Xml($string);
$result = $xml->toArray();
$expected = array('Rss' => array('version' => '2.0', 'Channel' => array('title' => 'Cake PHP Google Group', 'link' => 'http://groups.google.com/group/cake-php', 'description' => 'Search this group before posting anything. There are over 20,000 posts and it's very likely your question was answered before. Visit the IRC channel #cakephp at irc.freenode.net for live chat with users and developers of Cake. If you post, tell us the version of Cake, PHP, and database.', 'language' => 'en', 'Item' => array(array('title' => 'constructng result array when using findall', 'link' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f', 'description' => "i'm using cakephp to construct a logical data model array that will be <br> passed to a flex app. I have the following model association: <br> ServiceDay->(hasMany)ServiceTi me->(hasMany)ServiceTimePrice. So what <br> the current output from my findall is something like this example: <br><p>Array( <br> [0] => Array(", 'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'), 'author' => 'bmil...@gmail.com(bpscrugs)', 'pubDate' => 'Fri, 28 Dec 2007 00:44:14 UT'), array('title' => 'Re: share views between actions?', 'link' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8', 'description' => 'Then perhaps you might do us all a favour and refrain from replying to <br> things you do not understand. That goes especially for asinine comments. <br> Indeed. <br> To sum up: <br> No comment. <br> In my day, a simple "RTFM" would suffice. I\'ll keep in mind to ignore any <br> further responses from you. <br> You (and I) were referring to the *online documentation*, not other', 'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8'), 'author' => 'subtropolis.z...@gmail.com(subtropolis zijn)', 'pubDate' => 'Fri, 28 Dec 2007 00:45:01 UT')))));
$this->assertEqual($result, $expected);
$string = '<data><post title="Title of this post" description="cool"/></data>';
$xml = new Xml($string);
$result = $xml->toArray();
$expected = array('Data' => array('Post' => array('title' => 'Title of this post', 'description' => 'cool')));
$this->assertEqual($result, $expected);
$xml = new Xml('<example><item><title>An example of a correctly reversed XMLNode</title><desc/></item></example>');
$result = Set::reverse($xml);
$expected = array('Example' => array('Item' => array('title' => 'An example of a correctly reversed XMLNode', 'desc' => array())));
$this->assertIdentical($result, $expected);
$xml = new Xml('<example><item attr="123"><titles><title>title1</title><title>title2</title></titles></item></example>');
$result = $xml->toArray();
$expected = array('Example' => array('Item' => array('attr' => '123', 'Titles' => array('Title' => array('title1', 'title2')))));
$this->assertIdentical($result, $expected);
$xml = new Xml('<example attr="ex_attr"><item attr="123"><titles>list</titles>textforitems</item></example>');
$result = $xml->toArray();
$expected = array('Example' => array('attr' => 'ex_attr', 'Item' => array('attr' => '123', 'titles' => 'list', 'value' => 'textforitems')));
$this->assertIdentical($result, $expected);
$xml = new Xml('<example attr="ex_attr"><item attr="123"><titles>list</titles>textforitems</item></example>');
$example = $xml->child('example');
$item = $example->child('item');
$result = $item->toArray();
$expected = array('attr' => '123', 'titles' => 'list', 'value' => 'textforitems');
$this->assertIdentical($result, $expected);
$string = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rss version="2.0">
<channel>
<title>Cake PHP Google Group</title>
<link>http://groups.google.com/group/cake-php</link>
<description>Search this group before posting anything. There are over 20,000 posts and it&#39;s very likely your question was answered before. Visit the IRC channel #cakephp at irc.freenode.net for live chat with users and developers of Cake. If you post, tell us the version of Cake, PHP, and database.</description>
<language>en</language>
<item>
<title>constructng result array when using findall</title>
<link>http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</link>
<description>i'm using cakephp to construct a logical data model array that will be <br> passed to a flex app. I have the following model association: <br> ServiceDay-&gt;(hasMany)ServiceTi me-&gt;(hasMany)ServiceTimePrice. So what <br> the current output from my findall is something like this example: <br> <p>Array( <br> [0] =&gt; Array(</description>
<dc:creator>cakephp</dc:creator>
<category><![CDATA[cakephp]]></category>
<category><![CDATA[model]]></category>
<guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</guid>
<author>bmil...@gmail.com(bpscrugs)</author>
<pubDate>Fri, 28 Dec 2007 00:44:14 UT</pubDate>
</item>
<item>
<title>Re: share views between actions?</title>
<link>http://groups.google.com/group/cake-php/msg/8b350d898707dad8</link>
<description>Then perhaps you might do us all a favour and refrain from replying to <br> things you do not understand. That goes especially for asinine comments. <br> Indeed. <br> To sum up: <br> No comment. <br> In my day, a simple &quot;RTFM&quot; would suffice. I'll keep in mind to ignore any <br> further responses from you. <br> You (and I) were referring to the *online documentation*, not other</description>
<dc:creator>cakephp</dc:creator>
<category><![CDATA[cakephp]]></category>
<category><![CDATA[model]]></category>
<guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/8b350d898707dad8</guid>
<author>subtropolis.z...@gmail.com(subtropolis zijn)</author>
<pubDate>Fri, 28 Dec 2007 00:45:01 UT</pubDate>
</item>
</channel>
</rss>';
$xml = new Xml($string);
$result = $xml->toArray();
$expected = array('Rss' => array('version' => '2.0', 'Channel' => array('title' => 'Cake PHP Google Group', 'link' => 'http://groups.google.com/group/cake-php', 'description' => 'Search this group before posting anything. There are over 20,000 posts and it's very likely your question was answered before. Visit the IRC channel #cakephp at irc.freenode.net for live chat with users and developers of Cake. If you post, tell us the version of Cake, PHP, and database.', 'language' => 'en', 'Item' => array(array('title' => 'constructng result array when using findall', 'link' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f', 'description' => "i'm using cakephp to construct a logical data model array that will be <br> passed to a flex app. I have the following model association: <br> ServiceDay->(hasMany)ServiceTi me->(hasMany)ServiceTimePrice. So what <br> the current output from my findall is something like this example: <br><p>Array( <br> [0] => Array(", 'creator' => 'cakephp', 'Category' => array('cakephp', 'model'), 'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'), 'author' => 'bmil...@gmail.com(bpscrugs)', 'pubDate' => 'Fri, 28 Dec 2007 00:44:14 UT'), array('title' => 'Re: share views between actions?', 'link' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8', 'description' => 'Then perhaps you might do us all a favour and refrain from replying to <br> things you do not understand. That goes especially for asinine comments. <br> Indeed. <br> To sum up: <br> No comment. <br> In my day, a simple "RTFM" would suffice. I\'ll keep in mind to ignore any <br> further responses from you. <br> You (and I) were referring to the *online documentation*, not other', 'creator' => 'cakephp', 'Category' => array('cakephp', 'model'), 'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8'), 'author' => 'subtropolis.z...@gmail.com(subtropolis zijn)', 'pubDate' => 'Fri, 28 Dec 2007 00:45:01 UT')))));
$this->assertEqual($result, $expected);
$text = "<?xml version='1.0' encoding='utf-8'?>\n\t\t <course>\n\t\t <comps>\n\t\t <comp>1</comp>\n\t\t <comp>2</comp>\n\t\t <comp>3</comp>\n\t\t <comp>4</comp>\n\t\t </comps>\n\t\t </course>";
$xml = new Xml($text);
$result = $xml->toArray();
$expected = array('Course' => array('Comps' => array('Comp' => array(1, 2, 3, 4))));
//.........这里部分代码省略.........
示例3: startup
/**
* The startup method of the RequestHandler enables several automatic behaviors
* related to the detection of certain properties of the HTTP request, including:
*
* - Disabling layout rendering for Ajax requests (based on the HTTP_X_REQUESTED_WITH header)
* - If Router::parseExtensions() is enabled, the layout and template type are
* switched based on the parsed extension. For example, if controller/action.xml
* is requested, the view path becomes <i>app/views/controller/xml/action.ctp</i>.
* - If a helper with the same name as the extension exists, it is added to the controller.
* - If the extension is of a type that RequestHandler understands, it will set that
* Content-type in the response header.
* - If the XML data is POSTed, the data is parsed into an XML object, which is assigned
* to the $data property of the controller, which can then be saved to a model object.
*
* @param object $controller A reference to the controller
* @return void
* @access public
*/
function startup(&$controller)
{
if (!$this->enabled) {
return;
}
$this->__initializeTypes();
$controller->params['isAjax'] = $this->isAjax();
$isRecognized = !in_array($this->ext, array('html', 'htm')) && in_array($this->ext, array_keys($this->__requestContent));
if (!empty($this->ext) && $isRecognized) {
$this->renderAs($controller, $this->ext);
} elseif ($this->isAjax()) {
$this->renderAs($controller, 'ajax');
}
if ($this->requestedWith('xml')) {
if (!class_exists('XmlNode')) {
App::import('Core', 'Xml');
}
$xml = new Xml(trim(file_get_contents('php://input')));
if (is_object($xml->child('data')) && count($xml->children) == 1) {
$controller->data = $xml->child('data');
} else {
$controller->data = $xml;
}
}
}