Welcome Guest, Not a member yet? Register   Sign In
Route with variable gives 404
#1

Hi all,

I'm new to CodeIgniter and have a routing issue.
What I try to do is add a variable to the URL to pass it into the method arguments.

I used this example from the CI manual:

PHP Code:
$routes->add('product/(:num)''Catalog::productLookupByID/$1'); 

The actual code to match my needs is:

PHP Code:
$routes->get('/backend/profile/''backend/Profile::index');
$routes->get('/backend/profile/(:num)''backend/Profile::index/$1'); 


The method in the controller is:

PHP Code:
public function index($var null): void
{
    echo $var;

    //some more stuff


When I run the URL http://localhost:8080/backend/profile/1

I expect it to echo "1".
But instead a 404 is thrown [Controller or its method is not found: \App\Controllers\backend::index]

This controller does exist, because when I remove the 1 from the URL, the page loads, however, it is echoing NULL obviously...

What is this beginner missing here???
Reply


Messages In This Thread
Route with variable gives 404 - by sjender - 12-11-2020, 07:50 AM
RE: Route with variable gives 404 - by neoneeco - 12-12-2020, 02:53 AM
RE: Route with variable gives 404 - by sjender - 12-14-2020, 03:38 AM
RE: Route with variable gives 404 - by ReivaxBird - 12-14-2020, 08:25 AM



Theme © iAndrew 2016 - Forum software by © MyBB