我如何从Codeigniter中的助手调用助手?

时间:2022-06-23 07:00:46

I'm writing some custom helpers in Codeigniter and I want to call some functions from other helper files like date, etc, in my helper. I keep getting "call to undefined function" errors. How can I reference other helper functions from my helper?

我在Codeigniter中写了一些自定义帮助器,我想在我的帮助器中调用其他帮助器文件中的一些函数,比如日期等。我不断收到“调用未定义的函数”错误。如何从助手中引用其他助手功能?

Thx

谢谢

D

d

2 个解决方案

#1


32  

As you can see from the source link provided, calling $this in reference to the CodeIgniter object is only available within your controllers, models and views. However to take full use of CodeIgniter's native resources from outside those, you simply have to make an instance of it like this:

从您提供的源链接可以看到,在引用CodeIgniter对象时调用$ this仅在控制器,模型和视图中可用。但是,为了充分利用CodeIgniter的外部资源,你只需要创建一个这样的实例:

$instanceName =& get_instance();

Then, to access those resources, instead of using $this->, you'd be using $instanceName->.

然后,要访问这些资源,而不是使用$ this->,您将使用$ instanceName->。

Source

资源

#2


15  

function first_function()
{
    $ci =& get_instance();
    $ci->load->helper('date');
    $mysql = '20061124092345';
    $unix = mysql_to_unix($mysql);
}

#1


32  

As you can see from the source link provided, calling $this in reference to the CodeIgniter object is only available within your controllers, models and views. However to take full use of CodeIgniter's native resources from outside those, you simply have to make an instance of it like this:

从您提供的源链接可以看到,在引用CodeIgniter对象时调用$ this仅在控制器,模型和视图中可用。但是,为了充分利用CodeIgniter的外部资源,你只需要创建一个这样的实例:

$instanceName =& get_instance();

Then, to access those resources, instead of using $this->, you'd be using $instanceName->.

然后,要访问这些资源,而不是使用$ this->,您将使用$ instanceName->。

Source

资源

#2


15  

function first_function()
{
    $ci =& get_instance();
    $ci->load->helper('date');
    $mysql = '20061124092345';
    $unix = mysql_to_unix($mysql);
}