I seach this group using "hasMany Pagination", find a lot
discussinos ,
like:
https://groups.google.com/group/cake-php/browse_thread/thread/aae95f8f58f5e8c/a033143ebae17e83?lnk=gst&q=hasMany+Pagination#a033143ebae17e83
https://groups.google.com/group/cake-php/browse_thread/thread/6f6d28cc5b7ddc91/03214958368ea95a?lnk=gst&q=hasMany+Pagination#03214958368ea95a
but i still have problems.
this is my code:
<?php
class UsersController extends AppController {
var $name = 'Users';
var $helpers = array('Html', 'Form');
var $paginate = array(
'User'=> array('limit' => 5),
'Post'=> array('limit' => 5
),
);
function index() {
$this->User->recursive = 0;
$this->set('users', $this->paginate());
}
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid User.', true));
$this->redirect(array('action'=>'index'));
}
$this->User->recursive = 0;
$this->set('user', $this->User->read(null, $id));
$this->User->Post->recursive = -1;
$datas = $this->paginate($this->User->Post,
array('Post.user_id'=>
$id ));
$this->set('posts',$datas);
}
?>
and the view.ctp
<div class="related">
<h3><?php __('Related Posts');?></h3>
<?php if (!empty($posts)):?>
<table cellpadding = "0" cellspacing = "0">
<tr>
<th><?php __('Id'); ?></th>
<th><?php __('Title'); ?></th>
<th><?php __('Content'); ?></th>
<th><?php __('User Id'); ?></th>
<th class="actions"><?php __('Actions');?></th>
</tr>
<?php
$i = 0;
// $posts = $this->paginate('Post', 'User.id =='.$user['User']
['id'] );
foreach ($posts as $post):
$class = null;
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
}
?>
<tr<?php echo $class;?>>
<td><?php echo $post['Post']['id'];?></td>
<td><?php echo $post['Post']['title'];?></td>
<td><?php echo $post['Post']['content'];?></td>
<td><?php echo $post['Post']['user_id'];?></td>
<td class="actions">
<?php echo $html->link(__('View', true),
array('controller'=>
'posts', 'action'=>'view', $post['Post']['id'])); ?>
<?php echo $html->link(__('Edit', true),
array('controller'=>
'posts', 'action'=>'edit', $post['Post']['id'])); ?>
<?php echo $html->link(__('Delete', true),
array('controller'=>
'posts', 'action'=>'delete', $post['Post']['id']), null,
sprintf(__('Are you sure you want to delete # %s?', true),
$post['Post']['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
<div class="paging">
<?php echo $paginator->prev('<< '.__('previous', true), array(),
null, array('class'=>'disabled'));?>
| <?php echo $paginator->numbers();?>
<?php echo $paginator->next(__('next', true).' >>', array(), null,
array('class'=>'disabled'));?>
</div>
now when view this URL: http://localhost/cakephp/users/view/1 , there
are five posts, that's good.
but the 'prev' and 'next' paging link can not work.
if i click the next link , the expected url is
http://localhost/cakephp/users/view/1/page:2,
but i got http://localhost/cakephp/users/view/page:2, missing the
view parameter 1.
so can i fix this .
thanks!
On Jun 26, 8:52 am, rain <[EMAIL PROTECTED]> wrote:
> Hi,gays.
>
> I have a User , and the User hasMany Posts, when view User, the
> cakephp will find the User's posts, but i donot want show all the
> post , i want using the paginate , how to do this?
>
> thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---