Codeigniter - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

CodeIgniter View

CodeIgniter View

shape Description

CodeIgniter View is the presentation side of MVC. View holds all the HTML files and as well as the output of any of the variables pushed from the controller. It does not have any database syntax. The view page can have various HTML elements webpage like head, body, headings and so on. View cannot be called directly like the controller.

Create CodeIgniter View

shape Description

All the Views are present in the folder application/views. Now for an example, create the file "splessons.php" in the same folder and enter the below code. [html] <!DOCTYPE html> <html lang = "en"> <head> <meta charset = "utf-8"> <title>View Example</title> </head> <body> <h3> Hello, <?php echo $name;?> </h3> </body> </html> [/html] In the above code, the data will be passed into the view from the controller using the variable "$name". Controller code in application/controllers/splessons.php file will be as shown below. [php] <?php class Splessons extends CI_Controller { public function index() { echo "This is default function."; } public function hi($name) { $data = array("name"=>$name); $this->load->view('hi', $data); } } ?> [/php] In the above code, consider $this->load->view('hi', $data); in which "hi" is the name of view file, which is being rendered. Now use the below URI to get the view output: [html]http://www.your-domain-name.com/Codeigniter/index.php/splessons/hi/John[/html] Here, in the above URI, "splessons" is the controller class name, "hi" is the method name, and "John" is the value passed into view. Finally, the output will be as follows.

Summary

shape Key Points

  • View is the presentation side of MVC.
  • Views are present in the folder application/views.