user225359
user225359

Reputation: 73

Header not appearing & Footer not correct

I'm following the instructions in the CodeIgniter Tutorial on the Static Page but the Header does not appear although the tab is labelled "CodeIgniter Tutorial" and the content of the Footer appears on the same line as the content of the Page.

This is the content of my Pages.php - application/controllers/Pages.php

<?php
 class Pages extends CI_Controller
 {
    public function view($page = 'home')
    {
    if ( ! file_exists(APPPATH.'/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);
    }
 }

This is the content of my header.php - application/views/templates/header.php

<html>
    <head>
            <title>CodeIgniter Tutorial</title>
    </head>
    <body>

            <h1><?php echo $title ?></h1>

This is the content of my footer.php - application/views/templates/footer.php

            <em>&copy; 2014</em>
    </body>
 </html>

This is the content of my routes.php - application/config/routes.php

$route['default_controller'] = 'pages/view';
$route['(:any)'] = 'pages/view/$1';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

This is one URL http://localhost/MyProject/index.php/pages/view

And this is the result;

Home

Hello World! © 2014

And this is the other URL http://localhost/MyProject/index.php/pages/view/about

And this is the result;

About

Hello World! © 2014

I've checked every page numerous times, tried re-booting, and tried another browser, and tried CodeIgniter Forum, all to no avail.

Can somebody explain where I'm going wrong?


Edited

In the header.php file I've changed

<h1><?php echo $title ?></h1>

to

<h3><?php echo $title ?></h3>

which makes the word "Home" decreases in size. The only file I can find the word "home" is Pages.php

public function view($page = 'home')

If I change that word to "CodeIgniter Tutorial" I get a 404 error.

The IE tab is labelled "CodeIgniter Tutorial"

I'm unsure if my expectations are correct, but this is the result that I'm expecting (but with "© 2014" at the bottom of the page);

CodeIgniter Tutorial

Hello World!

© 2014

Upvotes: 0

Views: 415

Answers (3)

user225359
user225359

Reputation: 73

I created a file at application/views/pages/CodeIgniter Tutorial.php

and changed

public function view($page = 'home')

to

public function view($page = 'CodeIgniter Tutorial')

in Pages.php

and changed

<em>&copy; 2014</em>

to

<p><br><br><em>&copy; 2014</em></br></br></p>

in footer.php

I can achieve close to my expectations and now realise my expectations were far too much for a simple piece of coding.

Upvotes: 0

user4419336
user4419336

Reputation:

I tested your project on my localhost and your pages controller is fine.

It just seems to be you need to either use p tags or div etc and then use css style sheets etc.

But instead of

<em>&copy; 2014</em>

</body>
</html>

Try

<p>&copy; 2014</p>

</body>
</html>

Proof

enter image description here

enter image description here

Upvotes: 0

Andr&#233; Laszlo
Andr&#233; Laszlo

Reputation: 15537

It seems like the files views/pages/about.php and views/pages/home.php are empty. Try writing something in them, for example:

views/pages/about.php

<i>This is the About page</i>

If the file exist, but is empty, you should get the result you're seeing, because this line will not render anything:

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

If the files don't exist, you should get some 404 output - so that's a bit weird. It could happen if the file application/errors/error_404.php is empty.

Upvotes: 0

Related Questions