Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 调用Codeigniter中的扩展助手函数时未定义函数_Php_Codeigniter_Codeigniter 3 - Fatal编程技术网

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');给你的控制器?是的,我已经试过了,但它给了我其他错误,说找不到。因为如果我这样做,它会在系统/助手/上查看我的文件,对吗?至少错误是这么说的。