Blog Details

Creating Static pages at CodeIgniter


                                
                                    <h2><strong>*Creating First Application at CodeIgniter:-</strong></h2>
&nbsp;

<strong>1)</strong>  First, we make controller, create a file name "pages.php"   Create a file    at <strong><dfn>application/controllers/pages.php</dfn></strong> with the following code.

&nbsp;

&lt;?php

class Pages extends CI_Controller{

public function view($page = 'home'){
<pre>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-&gt;load-&gt;view('templates/header', $data);
	$this-&gt;load-&gt;view('pages/'.$page, $data);</pre>
}
}

&nbsp;

<strong>2) </strong>Create the header at <strong><dfn>application/views/templates/header.php</dfn></strong> and add the following code.

&nbsp;

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;?php echo $title ?&gt; - CodeIgniter 2 Tutorial&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Hello Word&lt;/h1&gt;

&nbsp;

<strong>3)</strong> Open the routing file located at <strong><dfn>application/config/routes.php</dfn> </strong>and add the following two lines.

&nbsp;
<pre>$route['default_controller'] = 'pages/view';
$route['(:any)'] = 'pages/view/$1';

</pre>
&nbsp;
                                    


Categories

CodeIgnitor

Latest posts

13.05.14
Implementing CRUD Operations ¶

<ul> <li>Now comes the fun part. We would like t

13.05.14
View

<ol> <li><a href="http://www.yiiframework.com/do

13.05.14
Creating Model

<ol> <li><a href="http://www.yiiframework.com/do

Get Free Quote