Answer the question
In order to leave comments, you need to log in
Another stupid question. How to make your own config file?
Good afternoon.
I say this all the time, and I'll say it again - I'm not a php specialist at all, but I need to do it)
In the index.php file, simple variables are displayed, such as Company name $company_name, Company phone number &company_phone, and so on, there are many variables.
Some of them are clogged through the admin panel, and some I need to hide for personal use.
So that later it would be convenient to change just in one file.
What file to create (what format)? And how to refer to a specific line of a file?
Answer the question
In order to leave comments, you need to log in
create a config.php file (the name is not important)
in index.php, where you have html c header footer content body head
insert the following code at the very beginning of the file:
<?php
include 'config.php';
?>
<html>
<head>
...
<?php
$my_config = array(
'company' => 'Hello world',
'author' => 'Ivan Ivanov'
);
<?=$my_config['author']; ?>
Under configs, there is one very convenient approach: configs in class constants.
The meaning is as follows, create a basic config, for example, DefaultConfig.php, set the settings for the development environment
namespace MyVendor\MyProject\Config;
class DefaultConfig
{
const MYSQL_DSN = 'mysql:host=localhost;dbname=dbName';
const MYSQL_USER = 'some_user';
const MYSQL_PASS = 'some_password';
}
namespace MyVendor\MyProject\Config;
class Config extends DefaultConfig
{
}
$pdo = new PDO(
Config::MYSQL_DSN,
Config::MYSQL_USER,
Config::MYSQL_PASS
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question