我试图自动加载辅助函数。我在 autoload.php 中添加了帮助文件并在视图文件中调用了该函数,但它不起作用。
应用程序/配置/autoload.php
$psr4 = ['Config' => APPPATH . 'Config',
APP_NAMESPACE => APPPATH,
'App' => APPPATH,
'Helpers' => APPPATH . 'Helpers/MY_helper'];
应用程序/Helpers/My_helper.php
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
function chicking_helper(){
return 'welcome to helper function';
}
应用程序/视图/welcome_message.php
<h1>Welcome to CodeIgniter </h1>
<p class="version">version <?= CodeIgniter\CodeIgniter::CI_VERSION ?></p>
<?php
chicking_helper();
?>
应用程序/控制器/BaseController
class BaseController extends Controller
{
/**
* An array of helpers to be loaded automatically upon
* class instantiation. These helpers will be available
* to all other controllers that extend BaseController.
*
* @var array
*/
protected $helpers = ['url', 'file'];