我的助手类中有helpers / common_helper.php
在此页面中,我有以下代码:
x1 = 1.4999 # rounds to 1
x2 = 1.4999999999999999 # rounds to 2
print(round(x1))
print(round(x2))
现在我正尝试从控制器中调用此resFormat函数
我使用了以下代码:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Helper
{
public static function resFormat($response = array())
{
但是由于某些原因,我得到了对未定义函数response()的调用
在我的autoload.php中
public function test()
{
// GET FORM CONTENTs.
$paperFormat = $this->Paper_model->getTest();
$status = 200;
$response = array('param' => null, 'status' => $status, 'data' => $paperFormat);
return response()->json(Helper::resFormat($response), $status);
}
答案 0 :(得分:0)
仅因为将您的帮助程序文件声明为类,所以您不能直接调用帮助程序功能。
您的comm_helper.php应该是:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');?>
<?php
public static function resFormat($response = array())
{
// you code
}
?>