SEO Friendly Pretty URL for Blog, Any documentation or Easy Steps in Framework

7 days ago

suresh_shinde
Member | 2
+
+1
-

For blog it is difficult to route for every URL manually.
Can we get post content & create user friendly URL(SEO URL) By using slug instead of id in posts?

4 days ago

Felix
Member | 662
+
0
-

Hi. Thanks for the question.

In short way, yes, it's possible.

For example:

$router[] = new Route('blog/<post>', array(
    'presenter' => 'Front:Post',
    'action' => 'detail',
    'post'  =>  array(
        Route::FILTER_IN => function ($post) {
            return $this->postRepository->findBySlug($post);
        },
        Route::FILTER_OUT => function ($post) {
            return $post->slug;
        }
    ),
));

about an hour ago

suresh_shinde
Member | 2
+
0
-

Hello Felix, thank you for your reply.
Fetching data from database by post_id is working.

I am facing issue with findBySlug function in postRepository. I am not able to get post data from database, I have two tables.

Master Table post having fields as;

id ,
gallery_id ,
user_id ,
image ,
show_in_homepage ,
created_at ,
updated_at

Detail table post_translation having fields as;

id ,
translatable_id ,
caption ,
perex ,
text ,
latte ,
file ,
slug ,
title ,
keywords ,
description ,
start_date ,
end_date ,
 locale

Please help me to write function to get post data by slug instead id.

Board footer

Terms and conditions