• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Separating controllers so they can work on their own

#1
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?

Heart Heart ,
Mekaboo
Reply

#2
It sounds like this is the same issue as https://forum.codeigniter.com/thread-73395.html ?
Reply

#3
(04-21-2019, 09: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 Huh
Reply

#4
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.
Reply

#5
(04-22-2019, 09:15 AM)Wouter60 Wrote: 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.
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 Sad
Reply

#6
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');?>
This is the same as:
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!
Reply

#7
(04-22-2019, 11:54 AM)Wouter60 Wrote: 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');?>
This is the same as:
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!

BINGO!!
WOOHOOO!!
This is what I was looking for, THANKS A BUNCHES Heart Heart Heart
Reply

#8
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
allow from all

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

# Prevent file browsing
Options -Indexes

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.
Reply

#9
(04-22-2019, 11:44 PM)Wouter60 Wrote: 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
allow from all

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

# Prevent file browsing
Options -Indexes

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.

Thank you so very much Heart
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.