Welcome Guest, Not a member yet? Register   Sign In
Defining extra constants CI 4
#5

(This post was last modified: 03-30-2020, 09:01 AM by dave friend.)

(03-28-2020, 05:25 PM)ZoeF Wrote: Hey

I am rewriting some of my smaller projects to get the hang of CI 4. But some things I am now rewriting I want to be able to reuse aftwerward without to much of a hassle. So I am trying to not meddle to much with the files allready included within CI 4 folders. One of those things I want to do is create my own little config with my own constants in there. But for the love of god I am unable to get it working.

It might be something stupid but if anyone has any working example i would be gratefull. Or if you have a better way of going about it i am all ears.

Just note I am in no way a experienced programmer.

You can create a class in the Config namespace and use it just like any other class.

PHP Code:
<?php namespace Config;

use 
CodeIgniter\Config\BaseConfig;

class 
MyStuff extends BaseConfig
{
    define("FOO",  "something");

    public $bar "Hello World.";



Then when you want to use "MyStuff" you create an instance of it and use the public properties like any other class.

PHP Code:
<?php namespace App\Controllers;

class 
Home extends BaseController
{
    public function 
index()
    {
       $myStuff = new Config\MyStuff();
       echo 
$myStuff->bar;
    }

Reply


Messages In This Thread
Defining extra constants CI 4 - by ZoeF - 03-28-2020, 05:25 PM
RE: Defining extra constants CI 4 - by ZoeF - 03-29-2020, 05:06 AM
RE: Defining extra constants CI 4 - by InsiteFX - 03-29-2020, 07:46 AM
RE: Defining extra constants CI 4 - by dave friend - 03-30-2020, 08:59 AM
RE: Defining extra constants CI 4 - by kilishan - 03-30-2020, 11:21 AM
RE: Defining extra constants CI 4 - by ramonpuig - 04-27-2024, 09:44 AM
RE: Defining extra constants CI 4 - by luckmoshy - 04-27-2024, 10:47 PM
RE: Defining extra constants CI 4 - by InsiteFX - 04-27-2024, 10:57 PM



Theme © iAndrew 2016 - Forum software by © MyBB