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.