Issue
Here is my directory (the screen-shot in this link). Also I have one more file named config.php
which contains some variables, like this:
<?php
// db
$dbname = 'mydb';
$db_username = 'root';
$db_password = '';
// login
$l_email = 'some@one.com';
$l_password = 'mypas'
// details
$sleep_on_error = 1; // per sec
// and etc
// .
// .
// .
?>
As you see, I've some variables that are stored into config.php
file .. I may need each of those variable in every part of my project. So I need to make config.php
file accessible in the whole of project. So I can add config.php
file into composer to make it accessible in the whole of project. like this:
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
},
"files": [
"app/classes/config.php"
]
},
All I'm trying to do is implementing a easy-configuration-system for my project. Can please tell me am I doing that correctly? Or should I define a class for doing that? or all I'm doing is wrong and I should do something else?
In short, what's the best structure to make a configuration for the project?
Solution
The Laravel way is using config files. Create my.php
and put it in /config
directory and then access constant values globally:
config('my.variable')
Here's an example of my.php
:
<?php
return [
'variable' => 15,
'some-array' => [1, 2, 5],
];
Answered By - Alexey Mezenin
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.