CakePHP Set ::基于元素条件提取父数组

时间:2011-08-22 17:45:20

标签: cakephp extract

说我有这样的数组:

        [Option] => Array
            (
                [0] => Array
                    (
                        [id] => 30606
                        [option_description_id] => 1
                        [product_id] => 101512
                        [price] => 0
                        [OptionDescription] => Array
                            (
                                [id] => 1
                                [option_type_id] => 1
                                [name] => Factory
                                [short_name] => 
                                [sort_order] => 1
                                [OptionType] => Array
                                    (
                                        [id] => 1
                                        [name] => Warranty
                                        [seo_url] => warranty
                                    )

                            )

                    )

                [1] => Array
                    (
                        [id] => 30607
                        [option_description_id] => 2
                        [product_id] => 101512
                        [price] => 44.99
                        [OptionDescription] => Array
                            (
                                [id] => 2
                                [option_type_id] => 1
                                [name] => +2 Year Extended
                                [short_name] => 
                                [sort_order] => 2
                                [OptionType] => Array
                                    (
                                        [id] => 1
                                        [name] => Warranty
                                        [seo_url] => warranty
                                    )

                            )

                    )

我想提取OptionDescription的option_type_id ID为1的选项

有没有办法用Set :: extract?

轻松完成

1 个答案:

答案 0 :(得分:0)

嗯,当然,在我发布问题两分钟之后(经过几个小时的努力弄清楚),我意识到这是多么容易。

要提取父元素,请在路径语法中使用/..

因此,对于type_ids为2的所有选项,我的行将是:

Set::extract('/Option/OptionDescription[option_type_id=2]/..', $product);