[英]Laravel 4 - Read config files
How can i read the config files from laravel? 如何从laravel读取配置文件? For example for the database connection (app/config/database/.php) 例如,对于数据库连接(app / config / database / .php)
I want the mysql data from the config. 我想从配置中获取mysql数据。
For a package you do it like that: 对于一个包你可以这样做:
return Config::get('package::group.option');
But how to do it for the main files? 但是如何为主文件做到这一点?
我做Config::get('database.default')
例如。
To get the database connection parameters (server, username, password etc) if you're using MySQL, you can do this: 要获取数据库连接参数(服务器,用户名,密码等),如果您使用的是MySQL,则可以执行以下操作:
echo "Driver: " . Config::get('database.connections.mysql.driver') . "<br/>\r\n";
echo "Host: " . Config::get('database.connections.mysql.host') . "<br/>\r\n";
echo "Database: " . Config::get('database.connections.mysql.database') . "<br/>\r\n";
echo "Username: " . Config::get('database.connections.mysql.username') . "<br/>\r\n";
echo "Password: " . Config::get('database.connections.mysql.password') . "<br/>\r\n";
On my local development machine this gives: 在我的本地开发机器上,这给出:
Driver: mysql 驱动程序:mysql
Host: localhost 主持人:localhost
Database: local_dev_db 数据库:local_dev_db
Username: root 用户名:root
Password: not-my-real-pwd 密码:not-my-real-pwd
...obviously you should never show your password (or any of these other details) in your live app! ...显然你不应该在你的直播应用中显示你的密码(或任何其他细节)! But if it's just for your information on a local development machine you should be fine. 但如果它仅仅是为了您在本地开发机器上的信息,那么您应该没问题。
If you're not using MySQL, just replace mysql
with sqlite
or pgsql
or whatever. 如果你不使用MySQL,只需用sqlite
或pgsql
替换mysql
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.