Welcome Guest, Not a member yet? Register   Sign In
How to Routes for Function with parameter?
#1

I made module with following tree:

module\Blog
module\Blog\Config
module\Blog\Controller
module\Blog\View


I put Blog.php inside module\Blog\Controller with 2 below functions:


Code:
public function index()
{
  echo 'this is index!';
}

public function page($id)
{
    echo 'this is page = ' .$id;
}


and below Routes.php inside module\Blog\Controller

Code:
$routes->get('blog', '\Modules\Blog\Controllers\Blog::index');
$routes->get('blog/page/(:num)', '\Modules\Blog\Controllers\Blog::page\$1');


when I tried to execute http://localhost/blog ==> its working,
but when I try to trigger http://localhost/blog/page/1 ==> return 404 error 

How to declare the routes to pass Controller's function parameter the right way?
Reply
#2

Just replace last '\' to '/'

PHP Code:
$routes->get('blog/page/(:num)''\Modules\Blog\Controllers\Blog::page/$1'); 
Reply
#3

(11-18-2020, 04:57 AM)vitnibel Wrote: Just replace last '\' to '/'

PHP Code:
$routes->get('blog/page/(:num)''\Modules\Blog\Controllers\Blog::page/$1'); 

Superb!!, thanksss  Big Grin Big Grin Big Grin been hours looking for hint, someone should put this as an example in the documentation.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB