Php 调用Codeigniter中的扩展助手函数时未定义函数
我在Php 调用Codeigniter中的扩展助手函数时未定义函数,php,codeigniter,codeigniter-3,Php,Codeigniter,Codeigniter 3,我在application/helpers/中创建MY\u form\u helper.php,扩展form\u helper.php。功能如下: function alert($message,$type = 'success'){ $data = array( 'type' => $type, 'text' => $message ); return json_encode($data); } $this->load
application/helpers/
中创建MY\u form\u helper.php
,扩展form\u helper.php
。功能如下:
function alert($message,$type = 'success'){
$data = array(
'type' => $type,
'text' => $message
);
return json_encode($data);
}
$this->load->helper(array('form', 'url'));
echo alert('Wrong email or password');
在我的控制器中,我调用如下函数:
function alert($message,$type = 'success'){
$data = array(
'type' => $type,
'text' => $message
);
return json_encode($data);
}
$this->load->helper(array('form', 'url'));
echo alert('Wrong email or password');
但这给了我一个错误
Message: Call to undefined function alert()
那么,我在这里遗漏了什么或做错了什么 将您的
MY\u form\u helper.php
helper放置到应用程序/helper
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
function alert($message,$type = 'success'){
$data = array(
'type' => $type,
'text' => $message
);
return json_encode($data);
}
让我知道结果。如果您将其存储在正确的目录中,即
应用程序/helpers
,名称为MY_form_helper.php
那么它应该可以正常工作。现在,您应该将扩展添加到核心帮助程序:
$this->load->helper('form');
var_dump(alert('Wrong email or password'));
测试了我做了,但仍然出错。现在它说无法加载请求的文件:helpers/my_form_helper.phpdid您是否将my_form_helper.php helper保存到application/helper?它应该是application/helpers,对吗?是的,我已经把它放在那个文件夹里了。是的,那你把它装进去了吗$这个->加载->助手('MY_form_helper');给你的控制器?是的,我已经试过了,但它给了我其他错误,说找不到。因为如果我这样做,它会在系统/助手/上查看我的文件,对吗?至少错误是这么说的。