Welcome Guest, Not a member yet? Register   Sign In
Modules in CI4 - Helpers and Constants
#1

Hi All,
I am currently working on a project, where I am keeping all my code in a module. So my structure is as below:
Code:
-app
-mymodule
  -admin
    -Config
      -Constants.php
    -Helpers
      -functions_helper.php
  -frontend
-public
-vendor
.... (other standard folders)

Now everything else from Modules (Routes, Controllers, Views) is working fine as I have provided namespace in Autoload.php, but Helpers and Constants are not working as they are not classes. 
In app > Config > autoload.php, I tried to add files as well with correct path, but it is still not working.
Code:
public $files = [
        '/mymodule/admin/Helpers/functions_helper.php'
    ];

I can make it work if I make them classes, but before I do that way, I want to check how to make it work without making classes. 
I read CI guide at https://codeigniter4.github.io/userguide...ml#helpers , where it is written that "Helpers will be automatically discovered within defined namespaces when using the 
Code:
helper() 
function, as long as it is within the namespaces [b]Helpers[/b] directory:"
But it is not working. I tried that way as well in the Controller.

Code:
helper('MyModule\Admin\Helpers\functions');

Any idea from anyone?
Reply


Messages In This Thread
Modules in CI4 - Helpers and Constants - by encodedigital - 09-14-2023, 08:58 AM



Theme © iAndrew 2016 - Forum software by © MyBB