Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用contain时出现Cakephp 2.0怪异数组_合并错误_Cakephp_Array Merge_Contain - Fatal编程技术网

使用contain时出现Cakephp 2.0怪异数组_合并错误

使用contain时出现Cakephp 2.0怪异数组_合并错误,cakephp,array-merge,contain,Cakephp,Array Merge,Contain,当使用contain将数据限制在我需要的范围内时,我出现了一个奇怪的错误。这是我的地址 $this->Movie->contain(array( 'Review' => array( 'fields' => array('id', 'title', 'spoilers', 'body', 'created'), 'User' => array( 'fields' =>

当使用contain将数据限制在我需要的范围内时,我出现了一个奇怪的错误。这是我的地址

$this->Movie->contain(array(
        'Review' => array(
            'fields' => array('id', 'title', 'spoilers', 'body', 'created'),
            'User' => array(
                'fields' => array('id', 'username'),
                'Profile' => array('fields' => array('id', 'image_thumb_small'))
            ),
            'order' => 'Review.created DESC',
            'limit' => 2,
        ),
        'Movieupdates' => array(
            'User' => array('Profile' => array('fields' => 'image_thumb_small')),
            'order' => 'Movieupdates.created DESC',
            'limit' => 2
        ),
        'Actor' => array(
            'fields' => array('name', 'slug', 'image_thumb'),
        ),
        'Genre' => array(
            'fields' => array('name', 'id'),
        )
    ));
问题是Cakephp给我带来了两个错误:

Warning (2): array_merge() [function.array-merge]: Argument #1 is not an array [CORE\Cake\Model\Behavior\ContainableBehavior.php, line 400]

Warning (2): array_unique() expects parameter 1 to be array, null given [CORE\Cake\Model\Behavior\ContainableBehavior.php, line 400]
我认为问题与以下行有关(在contain:Review->User中):

如果我删除,一切都很好,但我不想所有的数据从用户,特别是不是密码,所以我必须限制

我的包怎么了?错误提示我应该在某处使用数组,但我不知道在哪里

编辑添加的查询结果

Array
(
    [Movie] => Array
        (
            [id] => 27
            [user_id] => 
            [title] => The Amazing Spider-Man
            [slug] => The_Amazing_Spider_Man_2012
            [year] => 2012
            [summary] => Peter Parker finds a clue that might help him understand why his parents disappeared when he was young. 
            [poster] => /files/movies/53cb8be658a2e04a21909e288cdcb8.jpg
            [poster_thumb] => /files/movies/53cb8be658a2e04a21909e288cdcb8_resized_101x150.jpg
            [backdrop] => /files/movies/backdrop/amazing_spider_man.jpg
            [rating] => 7.4285714285715
            [like_count] => 5
            [review_count] => 7
            [see_count] => 7
            [rating_count] => 14
        )

    [Movieupdates] => Array
        (
            [0] => Array
                (
                    [id] => 20
                    [user_id] => 4
                    [movie_id] => 27
                    [type] => 4
                    [info] => 26
                    [created] => 2012-12-08 11:06:18
                    [User] => Array
                        (
                            [id] => 4
                            [username] => Ceriksen
                            [email] => skdji@gmail.com
                            [password] => ---
                            [validation_code] => 082b7735cfb3a3d5c74547d702bd97f9af517870
                            [group_id] => 3
                            [created] => 2012-11-27 11:23:57
                            [modified] => 2012-11-27 11:23:57
                            [Profile] => Array
                                (
                                    [id] => 5
                                    [user_id] => 4
                                    [image] => /files/profiles/771a98602dc7849b2d004952f1f35f.jpg
                                    [image_thumb] => /files/profiles/771a98602dc7849b2d004952f1f35f_resized_130x130-2.jpg
                                    [image_thumb_medium] => 
                                    [image_thumb_small] => /files/profiles/771a98602dc7849b2d004952f1f35f_resized_30x30.jpg
                                    [name] => 
                                    [last_name] => 
                                    [bio] => 
                                    [country] => 
                                    [city] => 
                                )

                        )

                )

            [1] => Array
                (
                    [id] => 19
                    [user_id] => 4
                    [movie_id] => 27
                    [type] => 3
                    [info] => 10
                    [created] => 2012-12-08 11:06:08
                    [User] => Array
                        (
                            [id] => 4
                            [username] => Ceriksen
                            [email] => skdji@gmail.com
                            [password] => ---
                            [validation_code] => 082b7735cfb3a3d5c74547d702bd97f9af517870
                            [group_id] => 3
                            [created] => 2012-11-27 11:23:57
                            [modified] => 2012-11-27 11:23:57
                            [Profile] => Array
                                (
                                    [id] => 5
                                    [user_id] => 4
                                    [image] => /files/profiles/771a98602dc7849b2d004952f1f35f.jpg
                                    [image_thumb] => /files/profiles/771a98602dc7849b2d004952f1f35f_resized_130x130-2.jpg
                                    [image_thumb_medium] => 
                                    [image_thumb_small] => /files/profiles/771a98602dc7849b2d004952f1f35f_resized_30x30.jpg
                                    [name] => 
                                    [last_name] => 
                                    [bio] => 
                                    [country] => 
                                    [city] => 
                                )

                        )

                )

        )

    [Genre] => Array
        (
            [0] => Array
                (
                    [name] => Action
                    [id] => 11
                    [MoviesGenre] => Array
                        (
                            [id] => 56
                            [movie_id] => 27
                            [genre_id] => 11
                        )

                )

            [1] => Array
                (
                    [name] => Adventure
                    [id] => 12
                    [MoviesGenre] => Array
                        (
                            [id] => 57
                            [movie_id] => 27
                            [genre_id] => 12
                        )

                )

            [2] => Array
                (
                    [name] => Fantasy
                    [id] => 18
                    [MoviesGenre] => Array
                        (
                            [id] => 58
                            [movie_id] => 27
                            [genre_id] => 18
                        )

                )

        )

    [Actor] => Array
        (
            [0] => Array
                (
                    [name] => Emma
                    [slug] => Emma_Stone
                    [image_thumb] => /files/actors/d59efc7614151acb7ea5d08da47112_resized_30x30.jpg
                    [MoviesActor] => Array
                        (
                            [id] => 1
                            [movie_id] => 27
                            [actor_id] => 8
                        )

                )

            [1] => Array
                (
                    [name] => Andrew
                    [slug] => Andrew_Garfield
                    [image_thumb] => /files/actors/0a9354d741328f4cf3e2954641e4eb_resized_25x30.jpg
                    [MoviesActor] => Array
                        (
                            [id] => 2
                            [movie_id] => 27
                            [actor_id] => 9
                        )

                )

            [2] => Array
                (
                    [name] => Martin
                    [slug] => Martin_Sheen
                    [image_thumb] => /files/actors/2383fc87054b2e8b4249fc7e3ffba5_resized_30x27.jpg
                    [MoviesActor] => Array
                        (
                            [id] => 3
                            [movie_id] => 27
                            [actor_id] => 10
                        )

                )

        )

    [Review] => Array
        (
            [0] => Array
                (
                    [id] => 26
                    [title] => W00t
                    [spoilers] => 0
                    [created] => 2012-12-08 11:06:18
                    [user_id] => 4
                    [MoviesReview] => Array
                        (
                            [id] => 25
                            [movie_id] => 27
                            [review_id] => 26
                        )

                    [User] => Array
                        (
                            [id] => 4
                            [username] => Ceriksen
                            [Profile] => Array
                                (
                                    [id] => 5
                                    [user_id] => 4
                                    [image] => /files/profiles/771a98602dc7849b2d004952f1f35f.jpg
                                    [image_thumb] => /files/profiles/771a98602dc7849b2d004952f1f35f_resized_130x130-2.jpg
                                    [image_thumb_medium] => 
                                    [image_thumb_small] => /files/profiles/771a98602dc7849b2d004952f1f35f_resized_30x30.jpg
                                    [name] => 
                                    [last_name] => 
                                    [bio] => 
                                    [country] => 
                                    [city] => 
                                )

                        )

                )

            [1] => Array
                (
                    [id] => 25
                    [title] => Testing the update
                    [spoilers] => 1
                    [created] => 2012-12-08 11:04:44
                    [user_id] => 4
                    [MoviesReview] => Array
                        (
                            [id] => 24
                            [movie_id] => 27
                            [review_id] => 25
                        )

                    [User] => Array
                        (
                            [id] => 4
                            [username] => Ceriksen
                            [Profile] => Array
                                (
                                    [id] => 5
                                    [user_id] => 4
                                    [image] => /files/profiles/771a98602dc7849b2d004952f1f35f.jpg
                                    [image_thumb] => /files/profiles/771a98602dc7849b2d004952f1f35f_resized_130x130-2.jpg
                                    [image_thumb_medium] => 
                                    [image_thumb_small] => /files/profiles/771a98602dc7849b2d004952f1f35f_resized_30x30.jpg
                                    [name] => 
                                    [last_name] => 
                                    [bio] => 
                                    [country] => 
                                    [city] => 
                                )

                        )

                )

        )

)

解决了,我的控制有一个错误。愚蠢的一个

'User' => array('Profile' => array('fields' => 'image_thumb_small')),
应该是:

'User' => array('Profile' => array('fields' => array('image_thumb_small'))),

不确定这是否是您的问题,但我认为您不能使用任何条件,如顺序和限制。这些应该在您的
find()
语句中。只使用条件和字段。实际上,您可以在contain中使用order和limit。它是有效的,实际上Cakebook中有一个例子在包含数组中使用了顺序:所以我怀疑这是问题所在,我使用的是read()而不是find()。但这也不会导致问题……好吧,我确实看到订单在那里,但我没有看到限制,我看到第302-314Hmm行,但删除限制并不能解决我的问题。奇怪的是,限制实际上在包含中工作得很好……哈哈,有了大量的配置文件选项,我真的想把它们分开。。。。
'User' => array('Profile' => array('fields' => array('image_thumb_small'))),