php - Calling the function inside helper file


I have inside my helper class inside helpers/common_helper.php

In this page I have following code:

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

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

Now I am trying to call this resFormat function from my controller

I have used following code:

public function test()
    $paperFormat = $this->Paper_model->getTest();

    $status = 200;
    $response = array('param' => null, 'status' => $status, 'data' => $paperFormat);
    return response()->json(Helper::resFormat($response), $status);


But for some reason I am getting call to undefined function response()

In my autoload.php

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



Just because declaring your helper file as class, so you can not call helper function directly.

your comm_helper.php should be:

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

People are also looking for solutions to the problem: php - How do we sum individual array elements in MongoDB aggregation query?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.