• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tutorial - Static Pages

#1
[eluser]Tybion[/eluser]
I relocated the application and system folders above the root of the web server as suggested in the CodeIgniter Installation Instructions.

As a raw CodeIgniter beginner, I am now running the Static Pages tutorial.

After I had created the first few files, the URL index.php/pages/view kept returning Page Not Found.

After a fair bit of research, I changed the code in pages.php to ..

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

The tutorial now works.

The code in the tutorial is currently ..
Code:
if ( ! file_exists('application/views/pages/'.$page.'.php')) {
Shouldn't this use the APPPATH definition?
Or is there an even better way to make sure the tutorial works in all cases?


#2
[eluser]jjDeveloper[/eluser]
Did you change the paths to your system and application folder in codeigniters index.php file?

#3
[eluser]Tybion[/eluser]
Yes
- to 'C:/CI/applications' and 'C:/CI/system'

That is why APPPATH is set to the new (correct) location rather than the original location.

#4
[eluser]CroNiX[/eluser]
I submitted a correction on github.

#5
[eluser]Phil Sturgeon[/eluser]
And it has been merged! Thanks for the fix guys.

#6
[eluser]desertprincess[/eluser]
Thanks...that fixed it. But I am stuck on the routes.php thing. Not sure if I should do this in routes.php or .htaccess with mod_rewrite. I am trying to rewrite/reroute the url www.myurl.com/pages/views/about to www.myurl.com/about without messing up other applications.
In routes.php I have:
Code:
$route['default_controller'] = 'news';
$route['404_override'] = '';

In .htaccess I have this one that I found:
Code:
<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /

    ### Canonicalize codeigniter URLs

    # If your default controller is something other than
    # "welcome" you should probably change this
    RewriteRule ^(pages(/index)?|index(\.php)?)/?$ / [L,R=301]
    RewriteRule ^(.*)/index/?$ $1 [L,R=301]

    # Removes trailing slashes (prevents SEO duplicate content issues)
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)/$ $1 [L,R=301]


    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php/$1 [L]

    # Checks to see if the user is attempting to access a valid file,
    # such as an image or css document, if this isn't true it sends the
    # request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule>

<IfModule !mod_rewrite.c>

    # Without mod_rewrite, route 404's to the front controller
    ErrorDocument 404 /index.php

</IfModule>
Thanks!

#7
[eluser]CroNiX[/eluser]
How many pages do you have like this? If not too many, you can list them all in a single route. There are many ways to do this.

Just one page...
Code:
$route['about'] = 'pages/view/$1';

Multiple pages...
Code:
$route['(about|some-other-page)'] = 'pages/view/$1';

Code:
class Pages extends CI_Controller {

  public function view($url_title = '')
  {
    // page name is sent as $url_title automatically
    if ($url_title !== '')
    {
      //check to see if page exists in database...

      //if so display it, if not show_404();
    }
  }
}

#8
[eluser]desertprincess[/eluser]
I have multiple pages, but I am thinking that it might be better to just not put them in the pages folder if it means adding an extra configuration.

#9
[eluser]msAdele[/eluser]
I'm learning a lot from the posts. Little by little, I hope I get to improve myself. Thanks, everyone!

#10
[eluser]igniter_guest[/eluser]
I am running through the 'Tutorial − Static pages' and I am having a problem on the first page!

I have followed the instructions in detail and all I get is error 404.
I included the APPPATH suggestion above but still no joy.

I am not having any joy with the documentation/tutorials on this site, anybody know of what might be wrong on the Static Pages tutorial?

Thanks in advance,
Jason


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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