Controller in a subfolder per user guide is not working |
[eluser]hal10001[/eluser]
I can't figure out why this isn't working. According to the user guide I should be able to put the controller in one subfolder and have it work. Here is my controller: application/controllers/admin/sites.php Code: <?php My view is at the following path: application/views/admin/sites.php I'm trying to hit the URL: http://www.mydomain.com/admin/sites
[eluser]Colin Williams[/eluser]
Me again. What error message do you receive.
[eluser]Tamer Solieman[/eluser]
Dear hal10001 Try to hit this URL http://www.mydomain.com/index.php/admin/sites
[eluser]Frank Berger[/eluser]
[deleted] sorry was to early here, no coffee yet.. forget what i said. Frank
[eluser]hal10001[/eluser]
[quote author="Colin Williams" date="1234006407"]Me again. What error message do you receive.[/quote] I get a 404. My directory structure looks like this: Code: -- system My controller: Code: <?php Code: -- system My view: Code: <html> I've read in other places developers talking about using routing to accomplish this, but according to the user guide, it really does look like I don't need routing if I'm following the rules and placing my controller in one subfolder and accessing the view where it is physically located. I'm sure this is something dumb, and I'm just missing it. Also, I'm not using "index.php" because I have this in my .htaccess: Code: RewriteEngine on
[eluser]TheFuzzy0ne[/eluser]
Have you set the variables correctly in both ./index.php and ./system/application/config/config.php? Based on the information you've give us, everything should work beautifully. If it doesn't, chances are something isn't configured correctly. It may also be wise to check that your server allows you to use .htaccess files, as some hosts don't. A simple way to check is to change the first line to something like: Code: RRewriteEngine on
[eluser]hal10001[/eluser]
It is a virtual host I setup on my local machine. I know the .htaccess is working because I can get to other controllers that are not in subfolders, and they work without the index.php in the URL. That is what is so weird about it. Do I need some sort of route for this to work, and the documentation on controllers in subfolders forgets to mention that? That seems like what is happening here because I'm getting the 404. It doesn't matter what view I try to load, it won't pull it from a controller in a subfolder. If I try to pull the view from a controller not in a subfolder, then I have no problems.
[eluser]TheFuzzy0ne[/eluser]
No. you should have no problems accessing a controller in a sub-directory, as long as that sub-directory is only one directory layer deep. Code: controllers http://mysite.tld/ http://mysite.tld/homepage http://mysite.tld/subdir1 http://mysite.tld/subdir1/homepage will all be valid URLs. Whereas: http://mysite.tld/subdir1/subdir2 http://mysite.tld/subdir1/subdir2/homepage will be invalid. If I were in your position, I would probably backup my CodeIgniter project, remove all traces of CodeIgniter, and start afresh. CodeIgniter will work the way you want it to, out of the box. Obviously, you will still need to do the primary configuration of CodeIgniter, and once that works, your controller could. One other possible cause may be that the controller or view file may not have the right permissions set, so CodeIgniter cannot open the file. I don't see how this could have happened, but anything is possible.
[eluser]hal10001[/eluser]
I have no idea why, but I did exactly what you said, and it works now. I deleted CodeIgniter, put another install in place, and did all the same things I did before, and now it works just fine. Absolutely crazy. Well, thanks everyone for your help on this one. I wish I had a more clearcut answer.
[eluser]hal10001[/eluser]
After some further testing I found out what the problem was, and I'm not sure if it is a bug, or if I missed something in the documentation. You can't have a folder name that is the identical name of a PHP file in the same directory. The problem is that I had a folder called admin, and in the same directory I had a file called admin.php. So I would type in www.mydomain.com/admin/sites and it was expecting admin.php to have a function called sites(). If I delete that file, it reads the folder, and then looks for a controller called sites, which is what I wanted. |
Welcome Guest, Not a member yet? Register Sign In |