Trying to change url link using routing with parameters not showing controller or action


#1

I’m trying to replace my url link with parameters passed using a link but I still want to controller and action to do their job.

What I want to do is change the url from http://localhost:8084/cakephp/posts/specific-post/132/damian_fenech/asdfad to http://localhost:8084/cakephp/posts/damian_fenech/asdfad.
Can anyone help me please?

Router:

Router::scope('', function (RouteBuilder $routes) {
        $routes->connect('/:id/:slug/:slug2',
            ['controller' => 'posts', 'action' => 'specificPost']
        )->setPass(['id']);
        $routes->fallbacks(DashedRoute::class);
});

Controller Action:
public function specificPost($id = null) {
$posts = TableRegistry::get(‘posts’);
$post = $posts->find(‘all’)->where([‘post_Id’ => $id])->contain(‘Users’)->contain(‘Comments’);
$all_posts = $post->toArray();
$this->set(“posts”, $all_posts);
}

Posts/index.ctp:
echo '<div class="col-sm">'.$this->html->link($post['post_Id'], ['controller' => 'posts', 'action' => 'specificPost',$post->post_Id, $post->user['first_name'].'_'.$post->user['last_name'], Inflector::slug($post['post_content'])]).'</div>';