Problems folowing the static page tutorial |
[eluser]plicatibu[/eluser]
Hi. I'm a brand new user of codeigniter and I started following the tutorial in http://ellislab.com/codeigniter/user-gui...pages.html To avoid typos I copied/pasted the code from the tutorial page. When I go to URL Code: http://127.0.0.1/citests the home.php page is show. But if I go to Code: http://127.0.0.1/citests/about I get the error The requested URL /citests/index.php/about was not found on this server. The only way I can see the about.php page is when I change the controller code from Code: class Pages extends CI_Controller { Code: class Pages extends CI_Controller { What am I missing? I'm running Ubuntu 12.04 In config.php the base_url = 'http://localhost/citests/' Thank you.
[eluser]DarkManX[/eluser]
i think you got something wrong, first you should get rid of the index.php in the url - looks pretty silly. there are several tutorials, just google. to call a certain page you gotta call the controller in the first segment and the action in the second. examples: page.org/home would link to the controller 'home' and to the action 'index' by default, because no action is given page.org/about would like to the controller 'about' and to the action 'index' page.org/about/show -> controller 'about', method 'show' you can set your own routes, but to start with ci its not necessary to do!
[eluser]plicatibu[/eluser]
Thank you for replaying. I'm sure I made something wrong. But I failed to see what I did. And I'm following the official codeigniter tutorial. The first part (after the installation) create static pages just like that. I believe that as I advance in the tutorial the sample will be refined. But I can't advance when I'm failing in the basic steps. Regards. [quote author="DarkManX" date="1346150947"]i think you got something wrong, first you should get rid of the index.php in the url - looks pretty silly. there are several tutorials, just google. to call a certain page you gotta call the controller in the first segment and the action in the second. examples: page.org/home would link to the controller 'home' and to the action 'index' by default, because no action is given page.org/about would like to the controller 'about' and to the action 'index' page.org/about/show -> controller 'about', method 'show' you can set your own routes, but to start with ci its not necessary to do![/quote]
[eluser]Aken[/eluser]
Is your About page's view located at /application/views/pages/about.php ? Did you add the routes?
[eluser]plicatibu[/eluser]
@Aken Yes. Following the Installation Instructions section I did the following: 1 - unziped codeigniter and moved it to /var/www. 2 - renamed the codeigniter folder name to citests. 3 - the structure is as follow: Code: /var/www/citests/ 4 - Now I can access the site using both http://127.0.0.1/citests/ and http://127.0.0.1/citests/index.php and I get the message Welcome to CodeIgniter! so everything is fine up to now. Note: I didn't moved nor renamed folders system and application so there is no need to change variables $system_folder and $application_folder in the /var/www/citests/index.php. Then I followed the Tutorial − Static pages: 5 - I created the file Code: application/controllers/pages.php Code: /var/www/citests/ 6 - I copied / pasted the content bellow to the file Code: application/controllers/pages.php Code: <?php 7 - I created the directory application/views/templates/ Code: mkdir -p application/views/templates/ 8 - I created the file application/views/templates/header.php Code: /var/www/citests/ 9 - I copied / pasted the following code into application/views/templates/header.php Code: <html> 10 - I created the file application/views/templates/footer.php 11 - I copied / pasted the following code into application/views/templates/footer.php Code: <strong>© 2011</strong> 12 - I created the directory application/views/pages/ Code: mkdir -p application/views/pages/ 13 - I create the files application/views/pages/home.php and application/views/pages/about.php and typed this is home and this is about respectively in them 14 - I copied / pasted the text bellow to controller application/controllers/pages.php Code: if ( ! file_exists('application/views/pages/'.$page.'.php')) so now it looks like the following: Code: public function view($page = 'home') 14 - At this point: if I type either http://127.0.0.1/citests/index.php/pages/view/ or http://127.0.0.1/citests/index.php/pages/view/home I see the page home.php. if I type http://127.0.0.1/citests/index.php/pages/view/about I see page about.php OK. Everything is fine up to now. 15 - In the routing section of static_page.html, it's required that I remove any routing in the file application/config/routes.php and put the following code in it; Code: $route['default_controller'] = 'pages/view'; Note: the routing code removed was Code: $route['default_controller'] = "welcome"; Now my problems started. After these changes in the file application/config/routes.php the URLs Code: http://127.0.0.1/citests/index.php/pages/view/ give me file not found error (and it seems issued by apache and not codeigniter). I tried the following URLs: Code: http://127.0.0.1/citests/ It shows the home.php as expected. But Code: http://127.0.0.1/citests/home doesn't work. Neither the URL http://127.0.0.1/citests/about As far as I understand from code in (14) the controller application/controllers/pages.php should used the end of the URLs to determine the page that would be exhibited (home or about). I made an experiment: I changed the default parameter from method view of controller code from Code: public function view($page = 'home') to Code: public function view($page = 'about') This way if I type the URL Code: http://127.0.0.1/citests/ it shows the about.php as expected. But Code: http://127.0.0.1/citests/about doesn't work. Neither the URL http://127.0.0.1/citests/home It seems the code only works when no parameter is passed to method and it uses the default value. So I'm sure that there is something wrong with code from view method of controller application/controllers/pages.php but I failed to see what it is. Or am I missing something? I'm using ci version 2.1.2. Thank you.
[eluser]fiziklgrfiti[/eluser]
Bumping this thread as the above post summarises the issue I'm experiencing.
[eluser]Unknown[/eluser]
you lose <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?> |
Welcome Guest, Not a member yet? Register Sign In |