Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Pagination
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
hill180  
View profile  
 More options Apr 25 2012, 7:29 pm
From: hill180 <hill...@gmail.com>
Date: Wed, 25 Apr 2012 16:29:26 -0700
Local: Wed, Apr 25 2012 7:29 pm
Subject: Pagination

Trying to use the paginator in the view

I have an Author who is has a Book and where the "book" was written (
book_id.name, city_id.name)
Author sort works, title sort work, but not the sort for city_id. I can
sort by the id, but obviously this won't work because
the id has nothing to do with the name of the city.

<th><?php echo $this->Paginator->sort('Author', 'name'); ?></th>
<th><?php echo $this->Paginator->sort('Book', 'title.name'); ?></th>
<th><?php echo $this->Paginator->sort('Where Written',
'title.city_id'); ?></th>
(sorts, but the names are not sorted because
it is using the id)

need something like this
<th><?php echo $this->Paginator->sort('Where Written', 'title.city_id.name');
?></th> //does not work.

Is there a way to get this to work, or is it a customer pagination?

thanks..
j


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
euromark  
View profile  
 More options Apr 25 2012, 8:38 pm
From: euromark <dereurom...@googlemail.com>
Date: Wed, 25 Apr 2012 17:38:45 -0700 (PDT)
Local: Wed, Apr 25 2012 8:38 pm
Subject: Re: Pagination

what version are you using?
because in 2.x it should be the other way around:

sort($key, $title)

please always mention your cake version

Am Donnerstag, 26. April 2012 01:29:26 UTC+2 schrieb Hill180:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
hill180  
View profile  
 More options Apr 26 2012, 12:57 am
From: hill180 <hill...@gmail.com>
Date: Wed, 25 Apr 2012 21:57:47 -0700
Local: Thurs, Apr 26 2012 12:57 am
Subject: Re: Pagination

1.3

On Wed, Apr 25, 2012 at 5:38 PM, euromark <dereurom...@googlemail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jeremyharris  
View profile  
 More options Apr 26 2012, 10:46 am
From: jeremyharris <funeralm...@gmail.com>
Date: Thu, 26 Apr 2012 07:46:09 -0700 (PDT)
Local: Thurs, Apr 26 2012 10:46 am
Subject: Re: Pagination

Is City a hasOne or belongsTo relationship? If so, and your find code is
using contain or recursive to include those in the results, you can do this:

$this->Paginator->sort('Where Written', 'City.name');

Check your data and SQL queries to see if it's joined that way.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
hill180  
View profile  
 More options Apr 26 2012, 6:06 pm
From: hill180 <hill...@gmail.com>
Date: Thu, 26 Apr 2012 15:06:34 -0700
Local: Thurs, Apr 26 2012 6:06 pm
Subject: Re: Pagination

City hasMany books, books only have one author.

City.name didn't work

var $hasMany = array(
        'Book' => array(
            'className' => 'Book',
            'foreignKey' => 'book_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ));


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jeremyharris  
View profile  
 More options Apr 26 2012, 6:13 pm
From: jeremyharris <funeralm...@gmail.com>
Date: Thu, 26 Apr 2012 15:13:35 -0700 (PDT)
Local: Thurs, Apr 26 2012 6:13 pm
Subject: Re: Pagination

If it's hasMany then I think your relationship should be:

var $hasMany = array(
        'Book' => array(
            'className' => 'Book',
            'foreignKey' => 'city_id', // books table has city_id
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ));

In that case, Book belongsTo City

class Book extends AppModel {
  var $belongsTo = array('City', 'Author');

}

Then you can paginate like the example I had above since it will LEFT join
the city models for all the books, as long as you contain the city model:

// in books controller
$this->paginate = array(
  'contain' => array('City', 'Author');
);
$this->paginate('Book'); // paginate from the book model to be able to sort
by Book, Author or City


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
hill180  
View profile  
 More options Apr 26 2012, 8:23 pm
From: hill180 <hill...@gmail.com>
Date: Thu, 26 Apr 2012 17:23:30 -0700
Local: Thurs, Apr 26 2012 8:23 pm
Subject: Re: Pagination

You know my example was a different then my actual code (I know I should
have just used it)

I have two cities per book.

IE

main_city_id (where it was written)
billing_city_id (where the author wants to get paid)

How do I distinguish them?  I can't use City.name

Thanks.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jeremyharris  
View profile  
 More options Apr 26 2012, 8:28 pm
From: jeremyharris <funeralm...@gmail.com>
Date: Thu, 26 Apr 2012 17:28:23 -0700 (PDT)
Local: Thurs, Apr 26 2012 8:28 pm
Subject: Re: Pagination

So the book belongsTo will look something like this:

var $belongsTo = array(
  'BillingCity' => array(
    'className' => 'City',
    'foreignKey' => 'billing_city_id'
  ),
  'MainCity' => array(
    'className' => 'City',
    'foreignKey' => 'main_city_id'
  ),
  'Author'
);

Then your pagination needs to contain both cities (or just the one you are
sorting by):

$this->paginate = array(
  'contain' => array('BillingCity', 'MainCity', 'Author');
);
$this->paginate('Book');

And lastly, your pagination link:

$this->Paginator->sort('Where Written', 'BillingCity.name'); // or MainCity


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
hill180  
View profile  
 More options Apr 27 2012, 7:45 pm
From: hill180 <hill...@gmail.com>
Date: Fri, 27 Apr 2012 16:45:16 -0700
Local: Fri, Apr 27 2012 7:45 pm
Subject: Re: Pagination

Here is the real example I am trying.

The webpage has a list of work order that are open.

<th><? echo $this->Paginator->sort('Work Order ID','WorkOrder.id') ?></th>
//works
<th><? echo $this->Paginator->sort('Customer','Customer.name') ?></th>
//works
<th><? echo $this->Paginator->sort('City','MainCity.name') ?></th> //no
worky

Customer Model:

var $belongsTo = array(
       'main_city' => array(
            'className' => 'City',
            'foreignKey' => 'main_city_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ),
        'billing_city' => array(
            'className' => 'City',
            'foreignKey' => 'billing_city_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ),...

  var $hasMany = array(
        'WorkOrder' => array(
            'className' => 'WorkOrder',
            'foreignKey' => 'customer_id',
            'dependent' => false,
        ),

Work Order Model

var $belongsTo = array(
        'Customer' => array(
            'className' => 'Customer',
            'foreignKey' => 'customer_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ),

City Model

  var $hasMany = array(
        'MainCity' => array(
            'className'=>'Customer',
            'foreignKey'=> 'main_city_id',
            'dependent'=>true,
        ),
              'BillingCity' => array(
            'className'=>'Customer',
            'foreignKey'=> 'billing_city_id',
            'dependent'=>true,
        ));


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jeremyharris  
View profile  
 More options Apr 27 2012, 7:50 pm
From: jeremyharris <funeralm...@gmail.com>
Date: Fri, 27 Apr 2012 16:50:04 -0700 (PDT)
Local: Fri, Apr 27 2012 7:50 pm
Subject: Re: Pagination

Why didn't you use the $belongsTo array I gave you? Your belongsTo has
changed the aliases from MainCity to main_city, so paginating by MainCity
will not work.

Rename the aliases to be CamelCased and try again. Also, debug the results
of $this->paginate() to make sure it includes the MainCity and any other
data you are trying to sort by.

-jeremy


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic