簡體   English   中英

調用幫助文件中的函數

[英]Calling the function inside helper file

我在 helpers/common_helper.php 里面有我的助手類

在此頁面中,我有以下代碼:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Helper
{
    public static function resFormat($response = array())
    {

現在我試圖從我的控制器調用這個 resFormat 函數

我使用了以下代碼:

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);

}

但出於某種原因,我正在調用未定義的函數 response()

在我的 autoload.php

$autoload['helper'] = array('common');

僅僅因為將你的幫助文件聲明為類,所以你不能直接調用幫助函數。

你的 comm_helper.php 應該是:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');?>
<?php
    public static function resFormat($response = array())
    {
      // you code 
    }
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM