• logo
  • PHP
  • PHP OOPs
  • script
    • JavaScript
    • JQuery
    • Ajax
    • AngularJs
    • VueJs
    • NodeJs
    • ReactJs
  • wordpress
  • Codeigniter
  • Codeigniter 4
  • Laravel
  • Python
  • MySql
  • Json
  • C
  • C++
  • More ...
    • Cakephp Framework
    • MongoDb
    • MySqli PDO
    • .htaccess
    • HTML 5
    • CSS
    • SEO
    • DCA

Codeigniter 4 Tutorials

  • Codeigniter 4
  • Application Run
  • Application Structure
  • Configuration files
  • Errors
  • Controller
  • View
  • Model
  • How to remove index.php from URL
  • Route
  • CodeIgniter URLs
  • Helper
  • Session
  • Global Functions and Constants
  • Logging Information in CI4
  • Error Handling
  • Signin / SignUp
  • Login / Register
  • CRUD
  • Crud 1
  • Form Validation
  • Data Table
  • Pagination
  • File Upload
  • Show Data Using Ajax
  • Select2 AJAX Autocomplete Search
  • Curl Post
  • Rest API
  • Weblink
Home » Codeigniter 4  » 

What is Config file Codeigniter 4?


You can access configuration files for your classes in several different ways.

File name : index.php

By using the new keyword to create an instance:

// Creating new configuration object by hand
$config = new \Config\Pager();

By using the config() function:

File name : index.php

// Get shared instance with config function
$config = config('Pager');

// Access config class with namespace
$config = config( 'Config\\Pager' );

// Creating a new object with config function
$config = config('Pager', false);

All configuration object properties are public, so you access the settings like any other property:

File name : index.php

$config = config('Pager');
// Access settings as object properties
$pageSize = $config->perPage;

Creating Configuration Files

When you need a new configuration, first you create a new file at your desired location. The default file location (recommended for most cases) is /app/Config. The class should use the appropriate namespace, and it should extend CodeIgniter\Config\BaseConfig

File name : index.php

<?php

namespace Config;

use CodeIgniter\Config\BaseConfig;

class CustomClass extends BaseConfig
{
public $siteName = 'My ittutorial';
public $siteEmail = 'info@ittutorial.in';

}

Environment Variables

Environment Variables by using a “.env” file.

.env to be at the root of your project alongside the system and app directories.

Settings are stored in .env files as a simple a collection of name/value pairs separated by an equal sign.

File name : index.php

S3_BUCKET = dotenv
SECRET_KEY = super_secret_key
CI_ENVIRONMENT = development

File name : index.php

When your application runs, .env will be loaded automatically, and the variables put into the environment. If a variable already exists in the environment, it will NOT be overwritten. The loaded Environment variables are accessed using any of the following: getenv(), $_SERVER, or $_ENV.

$s3_bucket = getenv('S3_BUCKET');
$s3_bucket = $_ENV['S3_BUCKET'];
$s3_bucket = $_SERVER['S3_BUCKET'];

File name : index.php


File name : index.php


File name : index.php


Output :-







Itechtuto

Connect Us Socially:

Quick Links

  • itech
  • About Us
  • Feedback
  • Trademarks
  • Privacy Policy
  • Terms of Use
  • Sitemap
  • Trademarks
  • Privacy Policy
  • Terms of Use
  • Sitemap

Copyright © 2016 itechxpert (P) Ltd. All rights reserved.

Copyright © 2016 itechxpert (P) Ltd. All rights reserved.