0

I need help here. This is my RestFul API And This is my source code :

ApiMover.php

<?php
 
 namespace App\Controllers\ApiData;
 use App\Controllers\BaseController;
 use CodeIgniter\RESTful\ResourceController;
 use App\Models\Dennis_medoo_model;


class ApiMover extends ResourceController
{    

    function __construct()
    {       
        
    }
    

    // equal to get    
    public function index()
    {          
       
        
    }
    
        
    // equal to post
    public function create() {
            

    }

    // equal to get
    public function show($com = null) {                
        
        
        if ($com != "topvalue" && $com != "topgainer") {

            $response = [
                'status'   => 103,
                'error'    => 'Command Error',
                'messages' => 'Command Must Be : topvalue Or topgainer',
                'data' => null                
            ];
    
            return json_encode($response);  
        }

        if ($com == "topvalue") {
            include 'Mover/topvalue.php';
        }


        if ($com == "topgainer") {
            include 'Mover/topgainer.php';
        }
        
    }

    // equal to put    
    public function update($id = null) {
        
    }
    

    // equal to delete
    public function delete($id = null) {        
            
    }

}

Inside my class ApiMover in function show() I have a custom helper function name aasort(). The helper name is "Dennis_utility_helper". I already load it automatically. But when I use class that extends ResourceController which it is a RestFul API the helper function aasort() cannot be found.

Is there a way to call my custom helper in class ApiMover extends ResourceController ?

Thank You

Dennis Liu
  • 2,268
  • 3
  • 21
  • 43
  • Does this answer your question? [How to autoload helper functions in codeigniter 4](https://stackoverflow.com/questions/41777261/how-to-autoload-helper-functions-in-codeigniter-4) – steven7mwesigwa Jan 31 '22 at 10:09
  • [How to create and load new helper in CodeIgniter 4](https://stackoverflow.com/questions/61883225/how-to-create-and-load-new-helper-in-codeigniter-4) – steven7mwesigwa Jan 31 '22 at 10:10
  • 1
    @steven7mwesigwa Thank you for the response, but I already found the solution I put it as answer. It is very a simple solution. And it worked. – Dennis Liu Jan 31 '22 at 10:44

2 Answers2

1

I found the solution. Just load manual the helper in the RestFul API example :

helper(Dennis_utility)
Dennis Liu
  • 2,268
  • 3
  • 21
  • 43
1

The ResourceController extend BaseResource which extend Controller so, in my opinion, you can simply use autoload helper functionality in the same way as in BaseController...

class MyApiController extends ResourceController
{
    protected $helpers = ['email', 'cookie'];
    ...
novluk
  • 11
  • 1