我正在使用 CodeIgniter 4 并按以下方式加载表单助手,但它仍然显示,
Call to undefined function form_open()
在 BaseController.php 中,我自动加载表单助手。
protected $helpers = ["form"];
路线:
$routes->get('admin/login', 'admin\LoginController::index');
Controller :
public function index()
{
echo view('admin/login');
}
查看:
<?php echo form_open('admin/dologin');?>
<?= csrf_token() ?>
<div class="input-group mb-3">
<input type="email" class="form-control" name="email" placeholder="Email">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-envelope"></span>
</div>
</div>
</div>
<div class="input-group mb-3">
<input type="password" class="form-control" name="password" placeholder="Password">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-lock"></span>
</div>
</div>
</div>
<div class="row">
<div class="col-4">
<button type="submit" class="btn btn-primary btn-block">Sign In</button>
</div>
<!-- /.col -->
</div>
<?php echo form_close();?>
我怎样才能摆脱这个错误?
Call to undefined function form_open()
最佳答案
This helper is loaded using the following code:
<?php helper('form');
在您的 app/Controllers/BaseController.php
文件中,
<?php
namespace App\Controllers;
// ...
class BaseController extends Controller
{
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
// Do Not Edit This Line
parent::initController($request, $response, $logger);
// Preload any models, libraries, etc, here.
helper("form");
}
}
关于php - 调用 CI 4 中未定义的函数 form_open(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73089822/