this questionと似ていますが、私のCakePHPに対する不満のために、私はこれを理解できないようです。ここに私のセットアップです。CakePHP:関連するhasManyフィールドのクエリ制約を使ったページネーション?
Comments
のモデル名User
があります。少なくとも1つのComment
を持つすべての不可視のリストUsers
が必要です。コントローラには、records
を$this->paginate()
と設定するメソッドがあり、値は渡されません。代わりに、$paginate
varは条件やそのようなもので設定されます。
class UsersController extends AppController {
var $name = 'Users';
var $paginate;
function new_users() {
$this->User->recursive = 1;
$this->paginate['User']['contain'][] = 'Comment';
$this->paginate['User']['order'] = 'User.DateCreated DESC';
$conditions = array();
// Get invisible users...
$conditions[] = array('User.Status = ?' => 'Invisible');
$conditions[] = array('User.Enabled' => true);
// ...with at least one active comment
$conditions[] = array('Comment.Status' => 'Active');
// Load these conditions and fire pagination to render the view
$this->paginate['User']['conditions'] = $conditions;
$this->set('records', $this->paginate());
}
}
私はCakePHPには新しく、このようなものはまだ私の頭の上にあります。私はちょうどアクティブComments
を持っているUsers
のリストがほしいです。今すぐ、このクエリはネットユーザー0人です。 Comment.Status
に関する行を削除すると、クエリは終了しますが、コメントがあるかどうかにかかわらず、すべて表示されません。Users
私がpaginate()
の電話を見たことのある場所では、何かが渡されました(paginate('User', array('Comment.Status' => 'Active'))
など)。
を編集してください:私は次のコードを持っていますが、クリーナーでも同じ結果が得られます。
$this->paginate = array(
'conditions' => array(
'User.Status' => 'Invisible',
'User.Enabled' => true,
),
'contain' => array(
'Comment' => array(
'conditions' => array(
'Comment.Status' => 'Active',
)
)
),
'recursive' => 1,
'order' => 'User.DateCreated DESC',
);
$data = $this->paginate('User');
あなたの助けを借りて、私は近づいています。私の見解では私のデータにアクセスできないようです。私は '$ this-> set( 'records'、$ data)'を使っています - 私のページネーション数は正確です(私の見解では1300+レコードが集まっています)。 '$ records'(私の見解ではそこには何もないようです)。 –
@BenjaminKreegerビューに送信する前にvar_dumo($ data)を試してください。データをフェッチしているかどうかはわかります(ページナンバーのコードを使用し、最後のgetQueryではなく、 – api55
'var_dump($ this-> paginate( 'User'))'は 'bool(false)'を表示します。あなたが答えに示したように '$ this-> paginate ='を設定しました。私はこの事を窓の外に投げる準備ができている。 –