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

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$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.

This question has been answered.

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

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

(6) Responses

See a threaded view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • 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

  • 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.

  • avatar
    Last edited:
    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.

  • avatar
    Last edited:
    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.

  • avatar
    Last edited:
    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/21/11
    2:32am
    sn says:

    Thanks.

This question has expired.



sn voted on this question.



Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.