Ask your Symfony questions! Pay money and get answers fast! (more info)

Symfony 1.4, Pager Navigation, additional URL parameters Symfony

  • SOLVED

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.

Answers (2)

2011-12-20

Luis Cordova answers:

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.


sn comments:

Thanks.

2011-12-20

Yura Rodchyn answers:

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]

<strong>blog_archive_without_page</strong>:
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, '@<strong>blog_archive_without_page</strong>?year='.$year.'&month='.$month) ?>


Yura Rodchyn comments:

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


sn comments:

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.


Yura Rodchyn comments:

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

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/<strong>*</strong>

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) ?>