Jump to content

lost with url and pagination


bwakad
 Share

Recommended Posts

Ryan suggested it's alway's better to use $input->get... I am not sure how to do this for my link, maybe it need to be changed I think?

But I hope someone can give me a solution to my pagination problem.

EDIT - based on Horst suggestion --------------- but still some issues

$input = wire("input");

My link on the template is this:

<a href="<?php echo $page->url;?>?sort=title">Title ASC</a>

In my function the code to retrieve the url is this:

    // get variable sort from url
    $sort = $input->get->sort;
    switch ($sort) {
        case 'title'  :  $sort="title";
                         break;
        case '-title' :  $sort="-title";
                         break;
        case 'id'     :  $sort="id";
                         break;    
        case '-id'    :  $sort="-id";
                         break;            
        default       :  $sort="{$page->name}";
                         break;
}

Then I looked for hours in the forum and finally used this from the skyscrapers, thinking sanitizing is good:

        // Do we have a get variable?
        if ($input->get->sort) {    
        // Sanitize it
        $sort = wire('sanitizer')->name(wire('input')->get->sort);
        // Add it to the whitelist... with the same name as the get var!  
        $input->whitelist('sort', $sort);
    }

I know there was something like: selectorValue, but I was unable to use it in the function

My $selector now is this (without a comma at the end), other wise I get errors:

  // create selector and expand with $sort value
  $selector = "template=child-template, limit=4 " . trim($selector, ", ");
  $selector .= ", sort=$sort";

Printing out the $selector while working displays: template=child-template, limit=4, branche

Finally, at the end of my function, after my $pages->find($selector); I have this code for my pagination,

now it uses the values:

$pagination = $selects->renderPager(array(
            'listMarkup' => "<ul class='MarkupPagerNav pagination'>{out}</ul>",
            'currentItemClass' => 'current'
        ));

This is now the only thing need to be adjusted:

My url's at the end now look like:

/pagename/page2?sort=title

Not sure if

/pagename/page=2/sort=title

/pagename/page2/sort=title

would be better, but it would be easier for the eye. Just don't know how to get the / after the page number...

Link to comment
Share on other sites

Yes, because the part behind the questionmark (in your case "?sort=titleASC") probably disappears if you're clicking a link. So you would have to add it to the pagination link as well.

Didn't read the first line :)

  • Like 1
Link to comment
Share on other sites

Maybe I'm reading your question wrong, but maybe try manually adding a '/' in your href when rendering the pagination

$pagination = $selects->renderPager(array(
            'listMarkup' => "<ul class='MarkupPagerNav pagination'>{out}</ul>",
            'currentItemClass' => 'current'
            ));
echo $pagination;
echo "<ul>";
foreach($selects as $select) {
echo "<li><a href='{$select->url}/?sort={$sort}'>{$select->title}</a></li>";
}
echo "</ul>";
echo $pagination;
Link to comment
Share on other sites

Maybe I'm reading your question wrong, but maybe try manually adding a '/' in your href when rendering the pagination

$pagination = $selects->renderPager(array(
            'listMarkup' => "<ul class='MarkupPagerNav pagination'>{out}</ul>",
            'currentItemClass' => 'current'
            ));
echo $pagination;
echo "<ul>";
foreach($selects as $select) {
echo "<li><a href='{$select->url}/?sort={$sort}'>{$select->title}</a></li>";
}
echo "</ul>";
echo $pagination;

That's not applicable since $select in your example represents one of the pages found in my page array.

The link I use is displayed on a current page, to send a ?sort=value  through the browser url.

The foreach comes after that link.

ps. If I use /?sort= it will mean:

/pagename//?sort= <<<<<<<<<<<<<<<< here it will not work...

/pagename/page2/?sort= <<<<<<<<<<< this is what I need: / after the page1 or page2 etc

Link to comment
Share on other sites

Just want the slash behind the page(1). Thought is was obvious, since I mentioned it twice.

I see something in the $config section: $config->pageNumUrlPrefix

but that is for BEFORE the 1 as in PAGE1

and what I would like is page1/

Link to comment
Share on other sites

@bwakad: yes you mentioned it, but I cannot follow your code. Also if I try to understand your answer to @Mindfull's post, I don't get it. I cannot find the link you mention there. Where is it, what does it looks like, why does it looks this way vs from where is it generated / created this way? Questions over questions for me. Sorry I cannot follow. :(

Link to comment
Share on other sites

lol. Beginning to think I talk hebrew / turkish or something... but it's really simple. Look in my first post, the second code!!!

I am talking about a link: <a href="<?php echo $page->url;?>?sort=title">Title ASC</a> (this is a link!!!)

Which translates in the browser url as:

http:host/pagename/?sort=title

But with pagination is:

http:host/pagename/page2?sort=title

I am after this:

http:host/pagename/page2/?sort=title

And I responded to mindfull "if I use it like /?sort=title"

the link will translate as:

http:host/pagename//?sort=title (double slash)

And with pagination is:

http:host/pagename/page2/?sort=title (correct)

Link to comment
Share on other sites

Great, if you have this, you only need to check your actual url for the string /page and if it matches, append a / and a ?sort= to it, and if not, only append ?sort= to it.

Ready. Done!

Happy coding!  :)

  • Like 1
Link to comment
Share on other sites

Did not found a good way for the slash and am uncertain if rewriting url is in fact a good way.

Then I tried to give the link a page name which does not exist. When I click on that I will in fact stay on the existing current page, and the browser url will display the non-existing page name after it.

That's url segment ! Which was in the beginning hard to understand for me :P . So that will solve the issue of the slash by default, and with pagination the page(nr) stays at the end.

Now I start rewriting some code to use this.

But I want to thank you, for your help on the $input wire. Learned a lot.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...