Welcome Guest, Not a member yet? Register   Sign In
Issue with BaseController and inheritance
#8

(This post was last modified: 07-23-2021, 12:02 AM by haroldentwist.)

(07-29-2019, 03:35 AM)SirTom Wrote: I have a problem with the BaseController and inheritance .

I am using Sub-Folders to organize my controllers. The controllers inherit from the BaseController is:


PHP Code:
<?php namespace App\Controllers;
use 
CodeIgniter\Controller;
class 
BaseController extends Controller
{ ... } 

<?
php namespace App\Controllers\Subfolder;
use 
App\Controllers\BaseController;
class 
MyController extends BaseController 
{ ... } 


The controller MyController has accesses to a protected function of the BaseController with:

PHP Code:
$this->baseControllerFunction(); 

In this function I use get_filenames from the filesystem-helper:

PHP Code:
$myCss get_filenames(FCPATH .'assets/css/'); 


So far this works. But the project is very complex and consists of several modules. So I want to add BaseControllers to each Sub-Folder, which inherit from the "global" BaseController.


PHP Code:
<?php namespace App\Controllers;
use 
CodeIgniter\Controller;
class 
BaseController extends Controller
{ ... }

<?
php namespace App\Controllers\Subfolder;
use 
App\Controllers\BaseController;
class 
SubfolderBaseController extends BaseController
{ ... }

<?
php namespace App\Controllers\Subfolder;
class 
MyController extends SubfolderBaseController 
{ ... } 


Now I get an error with the call:

PHP Code:
$this->baseControllerFunction(); 


Error-Message: Call to undefined function App\Controllers\get_filenames()

Why is the get_filenames function no longer available? The BaseController loads the helper for the filesystem with:


PHP Code:
protected $helpers = ['filesystem']; 


By inheritance the helper should be available in all subclases. So it is known to me from other object-oriented programming languages.

Thank you for your Support and Help!
Tom

You have a scripting problem. More specifically, you have a script conflict. An error was made during creation, which now prevents you from completing the project.
Reply


Messages In This Thread
RE: Issue with BaseController and inheritance - by haroldentwist - 07-22-2021, 12:38 AM



Theme © iAndrew 2016 - Forum software by © MyBB