Welcome Guest, Not a member yet? Register   Sign In
What am I missing on very basic tutorial "Static Pages"?
#1

[eluser]nielsentomazini[/eluser]
I am sorry everyone to come with something very basic. I am beginning to learn CI, following its User Guide but I don't understand one part of the tutorial.

It is written:
Quote:Adding logic to the controller

Earlier you set up a controller with a view() method. The method accepts one parameter, which is the name of the page to be loaded. The static page templates will be located in the application/views/pages/ directory.

In that directory, create two files named home.php and about.php. Within those files, type some text − anything you'd like − and save them. If you like to be particularly un-original, try "Hello World!".

In order to load those pages, you'll have to check whether the requested page actually exists:

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);

}

I have created all the pages that the tutorial teaches (pages.php, header.php. footer.php, home.php, about.php), but I did not understand where should I write this code above.

Where should it go?
Thanks in advance for any help.
#2

[eluser]nielsentomazini[/eluser]
Sorry bother,
I found my naivety. Believe me, I posted here because I tried dozens of time to figure out the problem.
Thanks!
#3

[eluser]williamxsp[/eluser]
Hey.

This piece of code goes at your controller. It should stay at controllers folders and named paged.php.
Then you can access in your_site_name/pages/page_name

I think that is.

W.

#4

[eluser]35mm[/eluser]
[quote author="nielsentomazini" date="1360086747"]Sorry bother,
I found my naivety. Believe me, I posted here because I tried dozens of time to figure out the problem.
Thanks![/quote]Ha ha I had the same issue when I did that tutorial today. Took me a while. I liked the tutorial because it made me think rather than just copy code and run.
#5

[eluser]nielsentomazini[/eluser]
Thanks everyone for taking the time to look at this post.

35mm, I agree, the tutorial is really good. I think the same as you.




Theme © iAndrew 2016 - Forum software by © MyBB