Php 在库中加载并调用帮助程序
如何在Codeigniter中调用库中的助手 我的代码:Php 在库中加载并调用帮助程序,php,codeigniter-2,helper,Php,Codeigniter 2,Helper,如何在Codeigniter中调用库中的助手 我的代码: class Upload { protected $ci; function __construct() { $this->ci =& get_instance(); // Load helper $this->ci->load->helper('form'); } function uploa
class Upload
{
protected $ci;
function __construct()
{
$this->ci =& get_instance();
// Load helper
$this->ci->load->helper('form');
}
function upload_file($file, $file_types = 'gif|jpg|png', $max_size = 1000, $max_width = 200, $max_height = 300)
{
// Set params
$config['upload_path'] = 'attached-files';
$config['allowed_types'] = $file_types;
$config['max_size'] = $max_size;
// Check if max_width is set equals to it is a image
if(isset($max_width))
{
$config['max_width'] = $max_width;
$config['max_height'] = $max_height;
}
// Try to upload the file
if (!$this->ci->upload->do_upload($file))
{
$data['profile_image_upload'] = array('error' => $this->ci->upload->display_errors());
}
else
{
$data['upload_data'] = $this->ci->upload->data();
}
return $data;
}
我试图建立一个通用库,当我想上传文件时,我会调用它,如果它是pdf、图像或其他文件,则为独立库
但我在以下代码中发现错误:
if (!$this->ci->upload->do_upload($file))
错误消息:
调用未定义的方法Upload::do_Upload()如果加载了帮助程序,您应该能够像下面这样调用该帮助程序中的函数:
do_upload($file);
所以换句话:
if (!$this->ci->upload->do_upload($file))
为此:
if (!do_upload($file))
当我这样做时,我会收到以下错误消息:
调用未定义的函数do\u upload()
。我是否在构造函数中加载了错误的函数?函数是否以你的表单上传?helper?@JohnSmith如果你移动$this->ci->load->helper('form'),会发生什么代码>下至功能上传文件
?你的助手功能是什么?助手必须是函数,而不是类。将其移动到函数调用未定义函数do\u upload()
时,我会收到相同的错误消息。do_upload()是CI中帮助器窗体的原始部分。所以我自己没有做任何事情。这都是标准的。还有其他建议吗?