• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New to CodeIgniter

#1
[eluser]davy_yg[/eluser]
Hello,

I am new to codeigniter, I am following code igniter tutorial:

Introduction:
Static Pages

Where should I add this codes:

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 don't really understand the instruction.

#2
[eluser]valuk[/eluser]
In controller.

#3
[eluser]davy_yg[/eluser]
in which file?

#4
[eluser]ppwalks[/eluser]
Probably welcome.php, did you change default controller?

#5
[eluser]davy_yg[/eluser]

ok, I just add them to welcome.php

Now I am trying to view:

localhost/CodeIgniter212/index.php/pages/view/about

I suppose to see the about page, yet I do not. I suppose to see the header and footer. I only see a blank page.


#6
[eluser]ppwalks[/eluser]
Load one view like your index, then load header and footer in the index, does that make sense?

Have you created the views in your views folder?

Blank page says no view available!

Comment out the views and simply echo something to check it loads ok

#7
[eluser]davy_yg[/eluser]

you mean creating views.php in views folder?

I have pages folder in views folder which consist of: about and home
I also have templates folder in views folder which consist of: footer and header


#8
[eluser]ppwalks[/eluser]
Can Recommend a book for you to work through "Wrox" "Professional Codeigniter", it will walk you through all the issues you have, seriously I think you need a good book!

#9
[eluser]davy_yg[/eluser]
Okay, I just get the ebook. There is too much information in it.

I am trying to get a hold of the basic from the CodeIgniter Tutorial / User Guide. Maybe it's faster.

#10
[eluser]Rolly1971[/eluser]
ok starting with your view files.

in folder: application/views

create the two folders: templates, and pages

in templates folder create or put the view files: header.php, footer.php

in pages folder put: home.php (as an example)

in application/controllers

create a file names: pages.php

in this file put the following code:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Pages extends CI_Controller {

function __construct()
{
  parent::__construct();    
}

public function index()
{
  $this->view();
}

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->vars($data);
  $this->load->view(‘templates/header’);
  $this->load->view(‘pages/’.$page);
  $this->load->view(‘templates/footer’);

}
}
/* End of file pages.php */
/* Location: ./application/controllers/pages.php */

that should do the trick


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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