#1
Hi all,

I have a blog site I have built and now adding pagination to the Home page where the blogs are published.

The function that creates the blog grid is called from within public.php.

in the Homepage controller file I have the following code to get the posts and create the pagination.
It is working , in that I get the page displaying with the pagination showing. However, when I click on page 2, I get a 404 error. I have noticed that in the url bar it is adding another slash before the page number, so I get http://localhost/dynamic_blog//2.

If I remove the duplicate / I still get a 404. I followed the documentation, but have clearly missed something.

#2
Hello,
How are you calling the pagination in the view file?
Are you using the Pagination::display($pagination_data); in the view file?
Dan
#3
Hi John,

Can you please share some more code, as the URL you have pasted is pointing to the index of your 'dynamic_blog' module, unless you have some custom routes going on?

http://localhost/dynamic_blog//2
#4
HI, i am using the correct code to call in my view file.


Dafa - the blog posts grid is displayed on the Home Page.

public.php calls a template partial for the header and footer. It then uses Modules::run to call the code I use to create the Hero / Slider
section.

Modules::run('homepage/_slider', $data)


It then uses Modules::run again to create the blog post grid

Modules::run('homepage/_get_all_posts', $data)

In this way , I assumed the pagination root would be the root

In Pagination.php we have



which in my eyes would no produce a duplicate /
#5
Hello,
Try commenting out the line:

//$pagination_data['pagination_root'] = '';

See if that makes a difference.
Maybe it's setting pagination_root to null.

Otherwise you can do a json($data, true) in pagination.php to see the data.

Dan
#6
Hi

I had tried removing that line before, but no banana.

The json I see is



I refactored to test and used the module / function in the way it usually is in say Manage, this meant I could actually pass a module and method in as the pagination root. This worked fine. So clearly it needs a module and method to work.

For the code to work, it needs to know what method to call and then feed in the page number, but it can't know what method to call if there isn't one in the url. So I need to somehow refactor this so that it know what method to call methinks.
#7
Just for fun.

You can try to set
page_num_segment to 0
And see what happens.

Also you can go to line 188 and check
json($pagination_data, true)

This should show the url or the root and current_page url
Also will show the prev and next

Dan
#8
I tried that earlier
#9
Have you tried.
$pagination_data['pagination_root'] = 'homepage/[view file name here]';
#10
problem is that anything I add into pagination root then appears in the url

http://localhost/dynamic_blog/homepage/grid-display/2 and then I get a 404.

I tried custom routing , but no joy.

A bit stuck I must admit.

Time for a beer and let the sub-conscious loose.