Welcome Guest, Not a member yet? Register   Sign In
Problems folowing the static page tutorial
#1

[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
http://127.0.0.1/citests/
http://127.0.0.1/citests/index.php
http://127.0.0.1/citests/index.php/home

the home.php page is show.

But if I go to

Code:
http://127.0.0.1/citests/about
http://127.0.0.1/citests/index.php/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 {
    public function view($page = 'home') {
to

Code:
class Pages extends CI_Controller {
    public function view($page = 'about') {

What am I missing?


I'm running Ubuntu 12.04
In config.php the base_url = 'http://localhost/citests/'

Thank you.
#2

[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!
#3

[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]
#4

[eluser]Aken[/eluser]
Is your About page's view located at /application/views/pages/about.php ?

Did you add the routes?
#5

[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/
                ├── application/
                ├── index.php
                ├── license.txt
                ├── system/
                └── user_guide/

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/
                ├── application/
                │              └─controllers/
                │                           └─pages.php
                ├── index.php
                ├── license.txt
                ├── system/
                └── user_guide/


6 - I copied / pasted the content bellow to the file
Code:
application/controllers/pages.php

Code:
<?php

class Pages extends CI_Controller {

public function view($page = 'home')
{

}
}


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/
                ├── application/
                │              └─controllers/
                │                           └─pages.php
                │              └─views/
                │                     └─templates/
                │                                └─header.php
                ├── index.php
                ├── license.txt
                ├── system/
                └── user_guide/


9 - I copied / pasted the following code into application/views/templates/header.php
Code:
<html>
<head>
<title><?php echo $title ?> - CodeIgniter 2 Tutorial</title>
</head>
<body>
<h1>CodeIgniter 2 Tutorial</h1>

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>&copy; 2011</strong>
&lt;/body&gt;
&lt;/html&gt;

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'))
{
  // Whoops, we don't have a page for that!
  show_404();
}

$data['title'] = ucfirst($page); // Capitalize the first letter

$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);

so now it looks like the following:
Code:
public function view($page = 'home')
{
  
if ( ! file_exists('application/views/pages/'.$page.'.php'))
{
  // Whoops, we don't have a page for that!
  show_404();
}

$data['title'] = ucfirst($page); // Capitalize the first letter

$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);

}


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';
$route['(:any)'] = 'pages/view/$1';

Note: the routing code removed was

Code:
$route['default_controller'] = "welcome";
$route['404_override'] = '';


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/
http://127.0.0.1/citests/index.php/pages/view/home
http://127.0.0.1/citests/index.php/pages/view/about

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.
#6

[eluser]fiziklgrfiti[/eluser]
Bumping this thread as the above post summarises the issue I'm experiencing.
#7

[eluser]Unknown[/eluser]
you lose

&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB