Blog Details

View



                                

* What is a View ?:-

  • view 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.
  • 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.

Example:-

Step 1 :

  • Let's create a simple View so you can see it in action. Using your text editor, create a file called blogview .php , and put the following code in it:
<html> <head> <title>My Blog</title> </head> <body> <h1>Welcome to my Blog!</h1> </body> </html>
  • Then save the file in your application/views/ folder.

Step 2 :

  • Let's create a simple controller so you can see it in action. Using your text editor, create a file called blog.php , and put the following code in it:
<?php class Blog extends CI_Controller { function index() {             $this->load->view('blogview'); } } ?>
  • If you visit your site using the URL you did earlier you should see your new view. The URL was similar to this:
  • localhost/codeigniter/welcome/index.php/blog/
 

* Loading multiple views:-

<?php class Page extends CI_Controller { function index() { $data['page_title'] = 'Your title'; $this->load->view('header'); $this->load->view('menu'); $this->load->view('content', $data); $this->load->view('footer'); } } ?>


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