2009年8月18日星期二

Re: [fw-mvc] Re: [fw-general] [fw-mvc] - Zend_Config_Xml with attributes

You can have multiple nodes with the same name. This is equal to the
ini-notation

item[] = a
item[] = b

Note that Zend_Config convert this into an array, but if you use Xml and
you have only a single node with this name, it will _not_ convert it

<item>a</item> <!-- string -->

<item>a</item> <!-- array key 0 -->
<item>b</item> <!-- array key 1 -->

Tom Graham schrieb:
> Hi,
>
> I may be mistaken but I don't think Zend_Config implements an Iterator
> interface so you probably can't do that. Also I don't think you can have
> multiple elements with the same name (at the same level). So
> "<items><item/><item/></items>" is not really a valid use of Zend_Config.
>
> Tom
>
> 2009/8/17 Vibhor Singh <vibhor@pivisions.net <mailto:vibhor@pivisions.net>>
>
> Thanks Tom for your quick help!
>
> So this means I can access the needed node using below lines:
>
>
>
> Suppose,
>
> |$config = new Zend_Config_Xml('/path/to/config.xml', '|mydata|');|
>
>
>
>
>
> foreach($config->items …..) {
>
>
>
> If(($config->items->type == 'clothes') { //can I
> check the 'type' attribute???
>
> //do all processing
>
> }
>
> }
>
>
>
> Thanks,
>
> Vibhor
>
>
>
> *From:* Tom Graham [mailto:tom.graham@jadu.co.uk
> <mailto:tom.graham@jadu.co.uk>]
> *Sent:* Monday, August 17, 2009 5:00 PM
> *To:* fw-mvc@lists.zend.com <mailto:fw-mvc@lists.zend.com>
> *Subject:* [fw-mvc] Re: [fw-general] [fw-mvc] - Zend_Config_Xml with
> attributes
>
>
>
> Hi,
>
> Yes it is possible, the attributes are the same as if you had a
> child element of the same name. For example:
>
> <mydata>
>
> <items type="clothes">
>
> <item belongs_to="cat1">
>
> <name>ABCD</name>
>
> </item>
>
> </items>
>
> </mydata>
>
> Is the same as if you did:
>
> <mydata>
>
> <items>
>
> <type>clothes</type>
>
> <item>
>
> <belongs_to>cat1</belongs_to>
>
> <name>ABCD</name>
>
> </item>
>
> </items>
>
> </mydata>
>
> Hope that helps,
>
> Tom
>
> 2009/8/17 Vibhor Singh <vibhor@pivisions.net
> <mailto:vibhor@pivisions.net>>
>
> Hi all,
>
>
>
> I want to use Zend_Config_Xml feature of ZF to automate my system. I
> am curious to know whether Zend_Config_Xml is able to read custom
> attributes of any xml file. If so, can someone please let me know
> how can this be achieved?
>
>
>
> My xml file would look something like this:
>
>
>
> <?xml version="1.0"?>
>
> <mydata>
>
> <items type="clothes">
>
> <item belongs_to="cat1">
>
> <name>ABCD</name>
>
> </item>
>
>
>
> <item belongs_to="cat3">
>
> <name>EFGH</name>
>
> </item>
>
> </items>
>
>
>
> <items type="shoes">
>
> <item belongs_to="cat5">
>
> <name>PQRS</name>
>
> </item>
>
>
>
> <item belongs_to="cat3">
>
> <name>XYZ</name>
>
> </item>
>
> </items>
>
>
>
> </mydata>
>
>
>
> Now suppose I want to access data under this node(<items
> type="shoes">), then how should I do this using the Zend_Config_Xml
> object.
>
> Can someone please help me in this? Any help would be greatly
> appreciated.
>
>
>
> Regards,
>
> Vibhor
>
>
>
>
>
>
>
>

--
Sebastian Krebs
http://www.kingcrunch2000.de
PGP key http://kingcrunch2000.de/public/0x44291B2B-pub.asc

没有评论: