Separating controllers so they can work on their own |
Hello all!
Besides the default controller I made another called Register with a function called pass. I added a button that would link from default controller to Register and it ends up showing a 404 error. I look in the url and this is what shows up: http://culturedkink.com/index.php/Welcom...ister/pass I realize no matter how many controllers I create it ends up being connected to the default (Welcome). How do I separate so they can function on their own? ![]() ![]() Mekaboo
It sounds like this is the same issue as https://forum.codeigniter.com/thread-73395.html ?
(04-21-2019, 08:12 PM)ciadmin Wrote: It sounds like this is the same issue as https://forum.codeigniter.com/thread-73395.html ? It's still not working. The default controller keeps popping up which causes an issue for the other controller to work ![]()
The button on your welcome page has this url:
Code: http://culturedkink.com/index.php/Welcome/index.php/Welcome/hello How did you create the link for that button? If I enter this url: Code: http://culturedkink.com/index.php/register/pass I get this text: Hello this is Meka! So, your controllers seem to work, but the links are messing things up. (04-22-2019, 08:15 AM)Wouter60 Wrote: The button on your welcome page has this url:When I type it in I get the same result which is great(I did that text as a test run) but I want that to show when someone press the button. Here is the link I made: <a href="index.php/Register/pass">Register a new membership</a> Here is the link for my Welcome page which works perfectly: <a href="index.php/Welcome/hello" class="button">ENTER</a> Im trying to figure out why 2 controllers/functions show up when Im only trying to request one? Im sooo confused ![]()
Don't include index.php in the links. CI will take care of that.
Add the site_url() config value to the URL's. If you use the anchor() function (in the url helper), CI will take care of that too! To get it working, check this value in config.php: PHP Code: $config['index_page'] = 'index.php'; Make sure you have this in autoload.php: PHP Code: $autoload['helper'] = 'url'; Then, in your view, generate links like this: PHP Code: <?= anchor('register/pass','Register a new membership');?> PHP Code: <?php echo '<a href="' . site_url() . 'register/pass' . '">Register a new membership</a>';?> That's all. You don't need a first capital letter in links, although the controller itself is named "Register.php". CI will take care of that. If you need a redirect in your controller to another controller or method: PHP Code: redirect('welcome/hello'); Good luck! (04-22-2019, 10:54 AM)Wouter60 Wrote: Don't include index.php in the links. CI will take care of that. BINGO!! WOOHOOO!! This is what I was looking for, THANKS A BUNCHES ![]() ![]() ![]()
Glad it's working now!!
To get rid of the index.php in all your URL's, just set the $config['index_page'] back to '' (empty string). Then modify your .htaccess file in the root of your website (where index.php is located): Code: order allow,deny Actually, .htaccess will insert the index.php part if it's missing in the url, but that's just what you want for all URL's. Now, users can access your website with URL's like: Code: http://culturedkink.com/register/pass All your "anchors" and redirects will still work. (04-22-2019, 10:44 PM)Wouter60 Wrote: Glad it's working now!! Thank you so very much ![]() |
Welcome Guest, Not a member yet? Register Sign In |