Home > Backend Development > PHP Tutorial > Detailed explanation of the method of loading views in CI framework view

Detailed explanation of the method of loading views in CI framework view

黄舟
Release: 2023-03-07 06:14:02
Original
1657 people have browsed it

This article mainly introduces CI (CodeIgniter)frameworkViewThe method of loading views in the CodeIgniter framework view is analyzed in the form of examples. Friends in need can refer to the following

The example of this article describes the loading of views in the CI (CodeIgniter) framework view. Method. Share it with everyone for your reference. The details are as follows:

As a lightweight framework of PHP, CI has many advantages. What I want to focus on here is loading views in views.

1: After setting the CodeIgniter database variable in the Application\config\database.php file, set the base URL in the Application\config\config.php file. For example, my base URL is: localhost/codeigniter. /

2: Next, create the default controller and view. The directory where the controller is created is: application\controllers\ folder. Create a controller named student.php . and set it as the default controller in application\config\routes.php

Controller->student.php

class Student extends CI_controller{
  public function construct(){
    parent::construct();
  }
  public function index(){
    $date['title']="Classroom:Home Page";
    $date['headline']="Welcome to the Classroom Management System";
    $date['include']="Student_index";
    $this->load->view('template',$date);
  }
}
Copy after login

views->template.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title><?php echo $title;?></title>
</head>
<body>
<h1><?php echo $headline;?></h1>
<?php $this->load->view($include);?>
</body>
</html>
Copy after login
.

view->student_index.php

Congratulations.Your initial setup is complate!

If you visit: localhost/CodeIgniter/index.php/student/index

the result will output:

Welcome to the Classroom Management System
Congratulations.Your initial setup is complate!
Copy after login

The above is the detailed content of Detailed explanation of the method of loading views in CI framework view. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template