Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter: Page not found when passing parameters to a controller?

I'm trying to pass parameters to a control in codeigniter, but I'm getting 404 page not found error, I don't get it, I did what the guide says: http://codeigniter.com/user_guide/general/controllers.html#passinguri

When I remove the params in the index function and just access the controller everything works fine, but I can't pass a value to it...

Here is the code the way I'm trying to send a param:

http://mysite/123

<?php
class Main extends Controller {

    function index($username) {

        echo $username;

    }

}
?>

How can I get more info regarding this error from codeigniter?

Thank you.

like image 787
thedp Avatar asked Mar 23 '26 05:03

thedp


1 Answers

With that URL, CodeIgniter can't understand if you want to pass 123 to the index method or if you're requesting the 123 method with no parameters. You have to explicitly name the default method if you need to pass it some parameters.

http://mysite/index/123
like image 138
Matteo Riva Avatar answered Mar 24 '26 19:03

Matteo Riva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!