logo

$5
Symfony 1.4, Pager Navigation, additional URL parameters

I'd like to create a pageable blog archive like this:

blog_archive:
url: /blog/archive/:year/:month/:page
class: sfDoctrineRoute
options: { model: Blog, type: list }
param: { module: blog, action: listArchive, page: 1 }
requirements:
year: \d+
month: \d+
sf_method: [get, post]


This works fine, creating including the pager:


public function executeListArchive(sfWebRequest $request) {
...
$this->pager = BlogTable::getInstance()->getArchivePager($page, $this->hitsperpage, $this->year, $this->month);


However, if I add the pager_navigation() to the Template like this:
<?php echo pager_navigation($pager, 'blog_archive') ?>
, I get an error message like "The "/blog/archive/:year/:month/:page" route has some missing mandatory parameters (:year, :month)." If I change the code to
<?php echo pager_navigation($pager, '@blog_archive?year='.$year.'&month='.$month) ?>
, the Pager doesn't work, because the page parameter isn't added to the URL.

sn | 12/20/11 at 11:09am | Edit

Previous versions of this question: 12/20/11 at 11:26am

(2) Possible Answers Submitted...

  • avatar
    Last edited:
    12/20/11
    11:17am
    Yura Rodchyn says:

    Hi,

    the solution can be additional route like:

    blog_archive:
    url: /blog/archive/:year/:month/:page
    class: sfDoctrineRoute
    options: { model: Blog, type: list }
    param: { module: blog, action: listArchive, page: 1 }
    requirements:
    year: \d+
    month: \d+
    sf_method: [get, post]

    blog_archive_without_page:
    url: /blog/archive/:year/:month
    class: sfDoctrineRoute
    options: { model: Blog, type: list }
    param: { module: blog, action: listArchive, page: 1 }
    requirements:
    year: \d+
    month: \d+
    sf_method: [get, post]


    And then call your pager navigation with <?php echo pager_navigation($pager, '@blog_archive_without_page?year='.$year.'&month='.$month) ?>

    Previous versions of this answer: 12/20/11 at 11:17am

    • 12/20/11 11:31am

      Yura Rodchyn says:

      Why there is no month and year? This route called @blog_archive so it means that there must be info like period of archive range.

    • 12/20/11 12:13pm

      sn says:

      My problem is not about the year / month parameter. If I change the the call to

      <?php echo pager_navigation($pager, '@blog_archive?year='.$year.'&month='.$month) ?>
      , year and month are added to the URL correctly. However, the page parameter is still missing.

    • 12/20/11 1:04pm

      Yura Rodchyn says:

      Yes, page is still required because you add it to the route url
      blog_archive:
      url: /blog/archive/:year/:month/:page

      If you want to pass only year and month and page to be optional you must remove :page from url. Like:

      blog_archive:
      url: /blog/archive/:year/:month/*

      And then you can pass as combination of (year,month) and also (year, month, .... <any you want params> )

      this will work

      <?php echo pager_navigation($pager, '@blog_archive?year='.$year.'&month='.$month) ?>


      and this will work too

      <?php echo pager_navigation($pager, '@blog_archive?year='.$year.'&month='.$month.'&page='.$page) ?>

  • avatar
    Last edited:
    12/20/11
    11:24am
    Luis Cordova says:

    of course there is no information about month year on <?php echo pager_navigation($pager, 'blog_archive') ?> call. You probably have to do your helper or do this in another way, but you cannot just call the helper in that way without parameters.

    • 12/21/11 2:32am

      sn says:

      Thanks.

This question has expired.



sn voted on this question.



Current status of this question: Completed