Welcome Guest, Not a member yet? Register   Sign In
[noob] Problem moving application & system folders outside root
#1

[eluser]johnnycho[/eluser]
A note before I begin: I've combed through the CI forum and Googled a variety of keyword combinations and I have yet to find someone experiencing the same problem I'm having. But if someone HAS brought this up before, I apologize and please send me the link.

I'm new to CI. I've installed the files on my server. One of the first things I did, as the CI documentation recommends, is to move my application and system folders outside the root. I then modified the appropriate path variables in the index.php. I'm fairly certain I did this properly, because the CI Welcome page shows up fine at http://mydomain.com/index.php.

I then started following the tutorial in the CI documentation (building the news app). I got as far as creating the header.php and footer.php files in /views/templates and the home.php and about.php files in /views/pages and then added the code for the Pages controller.

But when I go to http://mydomain.com/index.php/pages/view/about (as the doc says I can do), I get a 404 error.

Again, what's weird about this is that CI seems to have no trouble finding the welcome_message.php file in the /views directory. I can even make changes to the welcome_message.php file and those changes will show up fine on the Welcome page. So I think I have everything configured properly. But for some reason, it's not recognizing about.php and home.php.

What's weirder is that when I move the application and system folders to the root (same level as index.php) and modify the path variables accordingly, everything works fine -- I'm able to go to http://mydomain.com/index.php/pages/view/about and see the About page I created.

Anyone know why this may be happening? There seems to be a problem with moving the application and system folders outside the root? But that seems to be a recommended best practice! I've tried this on two different Web hosts and I'm having the same problem.

I'd be grateful for any assistance!

Thanks.
#2

[eluser]johnnycho[/eluser]
OK I figured it out. I'm stunned that no one else has run into this problem (that I can see). I guess no one who has taken the tutorial has moved their application & system folders outside the root, or vice versa.

So here's the deal: In the tutorial, it says to use the following code for your Pages controller class:

Code:
if ( ! file_exists('application/views/pages/'.$page.'.php'))
{
  // Whoops, we don't have a page for that!
  show_404();
}

Therein lies the problem. It's looking to see whether the file exists AT THE ROOT, not where the application folder actually exists.

If you add the correct path to the application folder, like this --

Code:
if ( ! file_exists('../../application/views/pages/'.$page.'.php'))
{
  // Whoops, we don't have a page for that!
  show_404();
}

-- it works just fine.

It seems the CI tutorial should add a comment about this for noobs like me.

Anyway, I hope this helps someone else.
#3

[eluser]CroNiX[/eluser]
Yeah, it should use the APPPATH or VIEWPATH constants defined in index.php

Code:
if ( ! file_exists(APPPATH . '/views/pages/'.$page.'.php'))
Code:
if ( ! file_exists(VIEWPATH . '/pages/'.$page.'.php'))
#4

[eluser]johnnycho[/eluser]
Even better! Thanks, CroNiX!
#5

[eluser]thebigpj[/eluser]
It took me 2 hours to find this post and figure this problem out.

Please either make a new page or remove that comment from the tutorial.

Thank you for posting this original thread.




Theme © iAndrew 2016 - Forum software by © MyBB