CakePHP和Set :: combine

时间:2012-08-19 16:25:12

标签: php arrays cakephp

我需要将其中每种语言的数据作为数组获取。 可能CakePHP中最好的方法是Set::combine,但无法使其正常工作。 我可以使用foreach手动完成,但我认为这不是最好的方式。

以下是示例:

Array
    (
        [Article] => Array
            (
                [id] => 131
                [title] => TEST
            )

        [titleTranslation] => Array
            (
                [0] => Array
                    (
                        [id] => 62
                        [locale] => eng
                        [model] => Article
                        [foreign_key] => 131
                        [field] => title
                        [content] => TEST
                    )
                [1] => Array
                    (
                        [id] => 63
                        [locale] => fre
                        [model] => Article
                        [foreign_key] => 131
                        [field] => title
                        [content] => Salva
                    )
                [2] => Array
                    (
                        [id] => 64
                        [locale] => rus
                        [model] => Article
                        [foreign_key] => 131
                        [field] => title
                        [content] => Пвет
                    )
            )
    )

进入这个数组:

Array
    (
        [Article] => Array
            (
                [id] => 131
                [title] =>  Array
                    (
                        [eng] => TEST
                        [fre] => Salva
                        [rus] => Пвет
                    )
            )

        .... the rest is not important

    )

解决-----

            $translatedData = Set::combine($this->data['titleTranslation'], '{n}.locale', '{n}.content', '{n}.field');
            $this->data['Article'] = array_merge($this->data['Article'], $translatedData);

0 个答案:

没有答案