Blog Details

View


                                
                                    <h2>* What is a View ?:-</h2>
<ul>
	<li>A <dfn>view</dfn> is simply a web page, or a page fragment, like a header, footer, sidebar, etc. In fact, views can flexibly be embedded within other views (within other views, etc., etc.) if you need this type of hierarchy.</li>
	<li>Views are never called directly, they must be loaded by a Controller. Remember that in an MVC framework, the Controller acts as the traffic cop, so it is responsible for fetching a particular view. If you have not read the Controllers page you should do so before continuing.</li>
</ul>
<h2><strong>Example:-</strong></h2>
<h2>Step 1 :</h2>
<ul>
	<li>Let's create a simple View so you can see it in action. Using your text editor, create a file called <strong>blogview .php</strong> , and put the following code in it:</li>
</ul>
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;My Blog&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Welcome to my Blog!&lt;/h1&gt;
&lt;/body&gt;
&lt;/html&gt;
<ul>
	<li>Then save the file in your <strong><dfn>application/views/</dfn> </strong>folder.</li>
</ul>
<h2>Step 2 :</h2>
<ul>
	<li>Let's create a simple controller so you can see it in action. Using your text editor, create a file called <strong>blog.php </strong>, and put the following code in it:</li>
</ul>
&lt;?php
class Blog extends CI_Controller {

function index()
{
<strong>            $this-&gt;load-&gt;view('blogview');</strong>
}
}
?&gt;
<ul>
	<li>If you visit your site using the URL you did earlier you should see your new view. The URL was similar to this:</li>
	<li><strong>localhost/codeigniter/welcome/index.php/<var>blog</var>/</strong></li>
</ul>
&nbsp;
<h2>* Loading multiple views:-</h2>
&lt;?php

class Page extends CI_Controller {

function index()
{
$data['page_title'] = 'Your title';
$this-&gt;load-&gt;view('header');
$this-&gt;load-&gt;view('menu');
$this-&gt;load-&gt;view('content', $data);
$this-&gt;load-&gt;view('footer');
}

}
?&gt;
                                    


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