<?php
// 这是一个简单的 CodeIgniter 示例代码,用于展示如何创建一个基本的控制器和视图。
// 1. 创建一个控制器文件 application/controllers/Welcome.php
class Welcome extends CI_Controller {
public function index()
{
// 加载视图文件
$this->load->view('welcome_message');
}
public function hello()
{
// 定义数据数组
$data['message'] = 'Hello, CodeIgniter!';
// 将数据传递给视图并加载视图文件
$this->load->view('hello_view', $data);
}
}
// 2. 创建一个视图文件 application/views/hello_view.php
<html>
<head>
<title>Hello CodeIgniter</title>
</head>
<body>
<h1><?php echo $message; ?></h1>
</body>
</html>
// 解释说明:
// - 控制器 `Welcome` 包含两个方法:`index` 和 `hello`。
// - `index` 方法加载默认的欢迎页面视图。
// - `hello` 方法定义了一个消息,并将其传递给视图 `hello_view.php`。
// - 在视图中,使用 `$message` 变量来显示传递的消息。
如果你需要更多关于 CodeIgniter 的详细信息或有其他问题,请告诉我!
上一篇:php 8.1
下一篇:php 字符串是否包含
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站