thanx brian,
but could you please explain your solution, because i'm new to cake.


On Apr 10, 3:19 pm, brian <[email protected]> wrote:
> If you want to use pagination, you'll have to make an initial query to
> find that month's sermons, then change the controller's $paginate
> array in your action like so:
>
> $this->paginate[KEY]['order'] = $num_sermons;
>
> Leave out the KEY part if you just have one "set" of paginate values.
>
> BUT, you're far better off just using find() instead. ie. no
> pagination. You could get the same effect by creating a series of
> links for each month, plus previous/next links. This would be simplest
> if you pass the number of the month (1-12). You could then set up a
> route with:
>
> Router::connect(
>         '/sermons/:month',
>         array(
>                 'controller' => 'sermons',
>                 'action' => 'index'
>         ),
>         array(
>                 'month' => '0[1-9]|1[012]',
>                 'pass' => 'month'
>         )
> );
>
> function index($month = null)
> {
>         if (is_null($month))
>         {
>                 /* get number for present month
>                  */
>                 $month = date('n');
>         }
>         // ...
>
> }
>
> BIG NOTE: the above assumes Julian dates. I don't know how to do the
> same for Hijri.
>
> Of course, you can also pass the name of the month, which might look better.
>
> On Thu, Apr 9, 2009 at 5:53 PM, ahmedhelmy007 <[email protected]> wrote:
>
> > Hi all.
>
> > A brief description of my problem:
>
> > I need to make pagination with non-fixed page size, every page must
> > contain items from certain month only. I wrote the query correctly ,
> > but the CAKE cannot count pages correctly because it calculates the
> > number of pages by dividing the total count of items by the page size -
> > the $limit variable- .
>
> > how can i make a custom paginateCount that returns the right number of
> > pages instead of the total count of items ?
> > I want a way to provide the CAKE with the number of pages instead of
> > leaving paginateCount to calculate it by dividing the total count of
> > items by the page size.
>
> > Is there any way to do this without hacking the core ? Or I will have
> > to dispense with the CAKE pagination and make my own one?
>
> > Detailed problem description:
>
> > I have a table called “sermons”  , each sermon have a “hijri_date”
> > field holds the sermon date.
>
> > The table is something like this:
>
> >     id     |   hijri_date   |
> > -------------|------------------|
> >     1      |  1429-1-1    |
> >     2      |  1429-1-8    |
> >     3      |  1429-1-15  |
> >     4      |  1429-1-22  |
> >     5      |  1429-3-5    |
> >     6      |  1429-3-12  |
> >     7      |  1429-4-4    |
>
> > I wanted to display sermons with pagination, each page contains the
> > sermon of a certain month.
>
> > According to the above table pages will be like this:
>
> > page 1 - all sermons that was in month #1 - :
>
> >    id      |   hijri_date   |
> > -------------|-------------------|
> >     1      |  1429-1-1    |
> >     2      |  1429-1-8    |
> >     3      |  1429-1-15  |
> >     4      |  1429-1-22  |
>
> > page 2 - all sermons that was in month #3 - :
>
> >    id      |   hijri_date   |
> > ------------|-------------------|
> >     5      |  1429-3-5    |
> >     6      |  1429-3-12  |
>
> > page 3  - all sermons that was in month #4 - :
>
> >    id      |   hijri_date   |
> > -------------|------------------|
> >     7      |  1429-4-4    |
>
> > The SQL query is like this:
>
> > SELECT *
> > FROM sermons
> > WHERE CONCAT(YEAR(hijri_date),'-',MONTH(hijri_date)) = (
> >                        SELECT DISTINCT( 
> > CONCAT(YEAR(hijri_date),'-',MONTH(hijri_date)))
> >                        FROM sermons
> >                        ORDER BY id DESC
> >                        LIMIT $offset , 1       )
> > ORDER BY id DESC
>
> > here are my controller and model
>
> > sermons_controller.php:
>
> > <?php
> > class SermonsController extends AppController {
> >        var $name = 'Sermons';
> >        var $paginate = array('Sermon' => array());
>
> >        function index() {
>
> >                if(! isset($this->passedArgs["page"])) $pageNumber=0;
> >                else $pageNumber=$this->passedArgs["page"]-1;
>
> >                $this->paginate = Set::merge($this->paginate,
> >                        array('Sermon'=>array('limit'=>2, 'page'=>1, 
> > 'extra'=>
> > $pageNumber)));
>
> >                $this->set('sermons', $this->paginate('Sermon'));
> >        }
>
> > }
> > ?>
>
> > and  sermon.php :
>
> > <?php
> > class Sermon extends AppModel {
> >        var $name = 'Sermon';
>
> >        function paginate($conditions, $fields, $order, $limit, $page = 1,
> > $recursive = null, $extra = array()) {
> >        global $Sermons;
>
> >                return $this->query(
> > "SELECT *
> > FROM sermons
> > WHERE
> >  CONCAT(YEAR(hijri_date),'-',MONTH(hijri_date)) = (
> >                        SELECT DISTINCT( 
> > CONCAT(YEAR(hijri_date),'-',MONTH(hijri_date)))
> >                        FROM sermons
> >                        ORDER BY id DESC
> >                        LIMIT $offset,1 )
> > ORDER BY id DESC");
>
> >        }
>
> >        function paginateCount($conditions = null, $recursive = 0, $extra =
> > array()) {
>
> >                $results =$this->query(
> > "SELECT COUNT(DISTINCT( CONCAT(YEAR(hijri_date),'-',MONTH
> > (hijri_date)))) AS monthes_count
> > FROM sermons”);
>
> >                return $results[0][0]["monthes_count"];
> >        }
>
> > ?>
>
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to