0

我正在使用以下 cakephp 查询从 mysql 检索数据:

    $tops = $this->PageBanner->find('all', array(
        'conditions' => array(
            'PageBanner.status' => 1
        ),
        'fields' => array(
            'PageBanner.page_url',
            'PageBanner.image',
            'PageBanner.logo',
            'PageBanner.logo_text',
            'PageBanner.content'
        )
    )); 

此查询返回以下结果:

  [0] => Array
    (
        [PageBanner] => Array
            (
                [page_url] => index
                [image] => home_banner.png
                [logo] => home_logo.png
                [logo_text] => abc 
                [content] => abc.
            )

    )

[1] => Array
    (
        [PageBanner] => Array
            (
                [page_url] => write_review
                [image] => kids2.png
                [logo] => home_logo.png
                [logo_text] => abc
                [content] => abc. 
            )

    )

但我希望数据以以下格式返回:

  [index] => Array
    (
                [page_url] => index
                [image] => home_banner.png
                [logo] => home_logo.png
                [logo_text] => abc
                [content] => abc.
    )

[write_review] => Array
    (
                [page_url] => write_review
                [image] => kids2.png
                [logo] => home_logo.png
                [logo_text] => abc
                [content] => abc. 
    )

我需要 page_url 字段内容来代替数组索引(ei 0、1)。是否可以获取这种格式的数据,或者我需要手动配置数组?

4

1 回答 1

1
$result = Set::combine($tops, '{n}.PageBanner.page_url', '{n}.PageBanner');
pr($result);
于 2012-12-10T09:55:37.057 回答