Welcome Guest, Not a member yet? Register   Sign In
Problem in accessing query in construct
#4

(08-08-2021, 03:18 PM)neto737 Wrote:
(08-08-2021, 01:18 AM)InsiteFX Wrote: Add a method in your BaseController to get the settings.
Example:
PHP Code:
protected function getSettings()
{
    return $this->settings;

Try that.

I tried to add this method in my BaseController, then did a var_dump in the another controller construct function but it returned null anyway.

I think the best workaround to this problem is using the CI4 Filters, but as I fetch all settings from database on BaseController, is there any way to use the data from this fetch instead of fetching it again on Filters?

The reason why I wanted to filter it on construct function is because I'll need to add this kind of filter to many pages individually, so creating Filters I'll need to create too many filters to verify if each page is enabled, is there any way to do this in a more "automatic"?

Since you don't want to use filter, you can try this.
  1. Create sub-BaseController controller extends BaseController and define your constructor and properties there. (E.g MyController or MasterController)
  2. Create your controller extends newly created sub-BaseController and create constructor with parent::__construct();

P/s: You can actually group the filter.
Reply


Messages In This Thread
RE: Problem in accessing query in construct - by nfaiz - 08-08-2021, 08:49 PM



Theme © iAndrew 2016 - Forum software by © MyBB