stooicrealism
stooicrealism

Reputation: 558

What is the use of the ($page = 'home' ) in this CodeIgniter method?

I was going through the CodeIgniter documentation and this bit of code confuses me as to why the method parameters is initialized to "home" as you can see below :

public function view($page = 'home') // why 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);

}

Could someone tell me why the method parameter is initialized as above?

Upvotes: 0

Views: 1351

Answers (1)

Michael Rice
Michael Rice

Reputation: 1183

That is a default value in PHP. If you call view(); without a value vs. view('somethingElse'); then it will default to 'home'.

Thus it will see if application/views/pages/home.php exists. If not, show_404(). Then it sets the title of the page = 'Home'. *Notice capital first letter.

Then it loads the header template view, page/home view, and template footer view.

Upvotes: 5

Related Questions