在 codeigniter 中调用未定义的方法 CI_Loader::section()
Call to undefined method CI_Loader::section() in codeigniter
目前我正在尝试在 codeigniter 的 views 文件夹下编写一个 AJAX 脚本。为此,我使用 <?= $this->section('scripts')?>
在 php 文件中创建了一个脚本。但是这样做会给我致命错误:调用未定义的方法 CI_Loader::section()。这是我的完整代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CodeIgniter MVC Basics</title>
</head>
<body>
<form method='post' action="index">
<h1>Customer Details</h1>
<input type="date" name="startDate"/>
<input type="date" name="endDate"/>
<select name="status">
<option>Draft</option>
<option>Unpublish</option>
<option>Let</option>
</select>
<br/><br/>
<button type="button" class="alertbox" name="alertbox">alertbox</button>
</form>
</body>
</html>
<?= $this->section('scripts')?>
<script>
$(document).ready(function(){
$(document).on('click', '.alertbox', function(){
alert("Hello world");
});
});
</script>
<?= $this->endsection()?>
我想要它,以便无论何时单击按钮,屏幕上都应该有一个警告弹出窗口。
编辑 我正在像这样从我的控制器加载视图:
$this->load->view('crm/test');
错误如下:
此代码:
$this->load->view('crm/test');
你就是这样 load a view in Codeigniter 3.
此代码:
<?= $this->section('scripts')?>
...
<?= $this->endsection()?>
正在使用layouts, from Codeigniter 4. So it looks like you're using CI4, but as shown on that layouts page, and in the main views documentation,在CI4中渲染和显示视图的方式不同:
echo view('crm/test');
目前我正在尝试在 codeigniter 的 views 文件夹下编写一个 AJAX 脚本。为此,我使用 <?= $this->section('scripts')?>
在 php 文件中创建了一个脚本。但是这样做会给我致命错误:调用未定义的方法 CI_Loader::section()。这是我的完整代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CodeIgniter MVC Basics</title>
</head>
<body>
<form method='post' action="index">
<h1>Customer Details</h1>
<input type="date" name="startDate"/>
<input type="date" name="endDate"/>
<select name="status">
<option>Draft</option>
<option>Unpublish</option>
<option>Let</option>
</select>
<br/><br/>
<button type="button" class="alertbox" name="alertbox">alertbox</button>
</form>
</body>
</html>
<?= $this->section('scripts')?>
<script>
$(document).ready(function(){
$(document).on('click', '.alertbox', function(){
alert("Hello world");
});
});
</script>
<?= $this->endsection()?>
我想要它,以便无论何时单击按钮,屏幕上都应该有一个警告弹出窗口。
编辑 我正在像这样从我的控制器加载视图:
$this->load->view('crm/test');
错误如下:
此代码:
$this->load->view('crm/test');
你就是这样 load a view in Codeigniter 3.
此代码:
<?= $this->section('scripts')?>
...
<?= $this->endsection()?>
正在使用layouts, from Codeigniter 4. So it looks like you're using CI4, but as shown on that layouts page, and in the main views documentation,在CI4中渲染和显示视图的方式不同:
echo view('crm/test');