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

About the method of loading views in CI framework view

不言
Release: 2023-04-01 07:20:02
Original
1814 people have browsed it

This article mainly introduces the method of loading views in the CI (CodeIgniter) frame view, and analyzes the related operating techniques of CodeIgniter frame view loading in the form of examples. Friends in need can refer to the following

The examples in this article describe Method of loading views in CI (CodeIgniter) framework view. 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 within views.

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

2: Next, create the default controller and view. The directory where the controller is created is: application\controllers\ folder. Create a A controller named student.php. and set it as default controller inside 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: http://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 entire content of this article, I hope it will be helpful to everyone Learning will be helpful. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

About the method of operating redis in the CI framework

The definition and usage of public model classes of the CI framework

The above is the detailed content of About 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