升级视图
文档
已更改内容
升级指南
- 首先,将所有视图移至文件夹 app/Views 
- 在加载视图的每个脚本中更改视图的加载语法
- 从 - $this->load->view('directory_name/file_name')更改为- return view('directory_name/file_name');
- 从 - $content = $this->load->view('file', $data, TRUE);更改为- $content = view('file', $data);
 
 
- (可选)可以将视图中的回显语法从 - <?php echo $title; ?>更改为- <?= $title ?>
- 如果存在,则删除行 - defined('BASEPATH') OR exit('No direct script access allowed');。
代码示例
CodeIgniter 版本 3.x
路径:application/views
<html>
<head>
    <title><?php echo html_escape($title); ?></title>
</head>
<body>
    <h1><?php echo html_escape($heading); ?></h1>
    <h3>My Todo List</h3>
    <ul>
    <?php foreach ($todo_list as $item): ?>
        <li><?php echo html_escape($item); ?></li>
    <?php endforeach; ?>
    </ul>
</body>
</html>
CodeIgniter 版本 4.x
路径:app/Views
<html>
<head>
    <title><?= esc($title) ?></title>
</head>
<body>
    <h1><?= esc($heading) ?></h1>
    <h3>My Todo List</h3>
    <ul>
    <?php foreach ($todo_list as $item): ?>
        <li><?= esc($item) ?></li>
    <?php endforeach ?>
    </ul>
</body>
</html>