蛋糕php分页不显示数组

时间:2013-12-15 14:20:28

标签: cakephp cakephp-2.0 cakephp-2.3

我正在尝试使用cakephp分页来检索数据。我错过了一个数组。当我尝试获取数据时,结果集中缺少 NewsFeedCommentLike 。我怎么能解决这个问题。我尝试了不同的方法,但没有任何工作,我真的很震惊。

谢谢..

这是我的代码:

$this->paginate = array(
            'conditions' => array('NewsFeed.group_id'=>$groupdata['Group']['id'],'NewsFeed.status'=>'A'),
            'joins' => array(
                    array(
                            'alias' => 'newslikes',
                            'table' => 'news_feed_likes',
                            'type' => 'LEFT',
                            'conditions' => array('newslikes.news_feed_id = NewsFeed.id','newslikes.user_id'=>$this->Auth->user('id'),'newslikes.status'=>'1')
                    )
            ),
            'fields' => array('IFNULL(newslikes.user_id,0) AS likestatus','NewsFeed.id','NewsFeed.posted_message','NewsFeed.created','NewsFeed.user_id','NewsFeed.status','NewsFeed.newslike'
                    ,'IFNULL(newslikes.status,0) AS status'),
            'order' => array(
                    'NewsFeed.created' => 'desc'
            )
    );

    $this->set('newsfeed', $this->paginate( $this->NewsFeed ) );

以下是我的结果:

array(
(int) 0 => array(
    (int) 0 => array(
        'likestatus' => '0',
        'status' => '0'
    ),
    'NewsFeed' => array(
        'id' => '12',
        'posted_message' => 'Test...',
        'user_id' => '2',
        'status' => 'A',
        'newslike' => '0'
    ),
    'Group' => array(),
    'User' => array(
        'password' => '*****',
        'id' => '2',
        'username' => 'sssss',
        'Email' => 'test@email.com',
        'facebook_id' => '0',
        'First_Name' => 'Sam',
        'avatar' => null,

    ),
    'NewsFeedComment' => array(
        (int) 0 => array(
            'id' => '16',
            'news_feed_id' => '11',
            'comments' => 'test reply',
            'user_id' => '1',
                    'created' => '2013-12-13 13:52:50',
            'replylikecount' => '0'
        )
    ),
    'NewsFeedLike' => array()
),

这些是我的模特:

NewsFeed.php

<?php
class NewsFeed extends AppModel {

var $name = 'NewsFeed';

var $useTable = 'news_feeds';
var $primaryKey = 'id';


var $hasMany = array(

        'NewsFeedComment' => array(
                'className' => 'NewsFeedComment',

        ),

        'NewsFeedLike' => array(
                'className' => 'NewsFeedLike',

        ),




);

var $belongsTo = array(
        'Group'=> array (
                'className' => 'Group',
                'foreignKey' => 'group_id'
        ),

        'User'=> array (
                'className' => 'User',
                'foreignKey' => 'user_id'
        )
);





}
?>

NewsFeedComment:

<?php
class NewsFeedComment extends AppModel {

var $name = 'NewsFeedComment';
var $useTable = 'news_feed_comments';
var $primaryKey = 'id';

var $hasMany = array(


        'NewsFeedCommentLike' => array(
                'className' => 'NewsFeedCommentLike',

        ),




);


var $belongsTo = array(
        'NewsFeed'=> array (
                'className' => 'NewsFeed',
                'foreignKey' => 'news_feed_id'
        ),

        'User'=> array (
                'className' => 'User',
                'foreignKey' => 'user_id'
        )
);

}
?>

NewsFeedLike.php

<?php
class NewsFeedLike extends AppModel {

var $name = 'NewsFeedLike';
var $useTable = 'news_feed_likes';
var $primaryKey = 'id';


var $belongsTo = array(
        'NewsFeed'=> array (
                'className' => 'NewsFeed',
                'foreignKey' => 'news_feed_id'
        ),

        'User'=> array (
                'className' => 'User',
                'foreignKey' => 'user_id'
        )
);

}
?>

NewsFeedCommentLike.php

<?php
class NewsFeedCommentLike extends AppModel {

var $name = 'NewsFeedCommentLike';
var $useTable = 'news_feed_comments_likes';
var $primaryKey = 'id';


var $belongsTo = array(

        'NewsFeed'=> array (
                'className' => 'NewsFeed',
                'foreignKey' => 'news_feed__id',

        ),

        'NewsFeedComment'=> array (
                'className' => 'NewsFeedComment',
                'foreignKey' => 'news_feed_comment_id',

        ),

        'User'=> array (
                'className' => 'User',
                'foreignKey' => 'user_id'
        )
);

}
?>

1 个答案:

答案 0 :(得分:0)

首先将条件减少到最低限度。然后添加条件,联接等,以查看问题可能从何处开始。

此外,遵循您的加入约定可能会有所帮助。将newslikes更改为NewsFeedLike