What I need to achieve is very simple logically, I use Laravel framework and need my users to be able to change few settings directly from a form rather than opening the settings file which look like this :
<?php
return array(
'driver' => 'gd'
);
So the question would be how to access a php array file based on key, an update the value ?
After getting settings with
$settings = require "settings.php";
You can populate the form and get changes submitted back. After you get ALL of the settings into $settings (not just the changed settings, all of 'em), you can write them back with
$php = "<?php return " . var_export($settings,true) . ";";
file_put_contents("settings.php", $php);
Related
I'm working on a laravel project and i have saved some pictures on a private storage folder .
This is config/filesystems.php :
'frontend' => [
'driver' => 'local',
'root' => storage_path('app/frontend'),
'url' => env('APP_URL') . '/storage/frontend',
],
I want to show images to client using rest api ( my client is a flutter application ) .
I have tried using some methods of File Storage in Laravel but it wont help .
This is a method that i have tried but when i use it's url it says to me Not Found:
Route::get('/show-pic', function () {
$pic = Picture::find(1);
$link = Storage::disk('frontend')->url($pic->avatar);
return response()->json($link , 200);
});
Also i dont want to get the content of pictures then return response containing content of picture ,
i just need url of picture .
Any suggestion will be helpful .
Thank you .
please try :
$link = Storage::disk('frontend')->getAdapter()->getPathPrefix();
or
$link = Storage::disk('frontend')->path($pic->avatar);
To solve this problem, you can use environment variables as follows:
APP_URL='your_app_url'
And then in your controller, you may access the url like this:
$imageUrl = $('APP_URL').'/uploads/'.$imageFileName;
this assumes that your image files are stored in storage/uploads
The easiest way to solve this issue :
Move your frontend folder inside storage\app\public
Then call
php artisan storage:link
And finally you may use the url method to get the URL for the given file
Storage::disk('public')->url('frontend/' . $pic->avatar);
I am trying to read/write my configuration in the DokuWiki.
The problem that occurs is when I am trying to call $this->getConf('url'); I always get the response from the conf/default.php file.
This is how my files look like:
admin.php
$url = $this->getConf('url');
conf/default.php
$conf['url'] = 'https://www.example.com';
conf/metadata.php
$meta['url'] = array('string', 'url' => 'https://correct-url.com');
And the value of $url always is:
https://www.example.com
I am not sure what I do wrong.
Thanks!
You may have some misunderstanding to DokuWiki's config system.
The config, which is editable by users, will be saved at /conf/local.php (not inside plugins!). The plugin can only provide a default value at default.php, while the metadata.php is to define how the value is shown on the frontend settings manager.
In your case, the correct URL will be shown, if the DokuWiki global config file (/conf/local.php for example) includes $conf["your_plugin_name"]["url"] = "https://correct-url.com";.
For more: https://www.dokuwiki.org/devel:configuration
I have created CRUD for global configuration parameters. I want to apply this parameters value as main config params (main.php).
I have found some way like add value of these parameters to any .inc file and perform read/write operation. Can anybody help me how can I achieve this? I am beginner in yii.
I have created table structure :
global_config :
Field | Value
pageSize | 20
admin_email| admin#example.com
main.php file as below :
.
.
{
'params' = array(
'pageSize' => 10,
'admin_email' => 'admin#example.com',
);
}
.
.
I am using config file as show above, I want to change it dynamically that it should get value from database.
So that I can make changes in config file from front-end side. I don't need to perform open/write action on main.php
In yii1 you can use params you can set this in main.php
'params'=>array(
'your_param'=>'your_value ',
...
Yii::app()->params['your_param'];
and you can set this value like a simple array poplulating the value form database
$param['yuor_param' =>$your_db_value];
You can't do this for params. As Application parameters are not really meant to be altered and if you change a value, it does not persist across different requests.
These are treated as constant in Yii, So you can't define them after running the script as config files runs at first as your code runs.
Finally, I found solution as per my requirement. I followed given below link from yii forum.
Link : http://www.yiiframework.com/wiki/304/setting-application-parameters-dynamically-in-the-back-end/
Thanks.
I have a file called settings.php that has all of the settings that the software uses. The problem is that I need users to be able to change the config without editing the file. I know I could do this with preg_replace but with dynamic settings like 'Board name' it would get tricky. I've tried a few things that didn't seem to work. I now you're not going to write the code for me, I just need a starting point.
Settings File
$settings = array (
'home_display'=>'home',
'db_host'=>'localhost',
'db_user'=>'root',
'db_password'=>'',
'db'=>'',
'login_enabled'=>true,
'signup_enabled'=>true,
'site_name'=>'Cheesecake Portal',
'b_url'=>'beta.cheesecakebb.org',
'b_email'=>'symbiote#cheesecakeb.org',
'board_enabled'=>true
);
The idea i have is to rewrite the file on the fly, even if i think this isnt the best way, it's a way.
if( file_exists($mySettingsFile) ){
include($mySettingsFile);
}
else{
$settings = array ( // the default settings array
'home_display'=>'home',
'db_host'=>'localhost',
'db_user'=>'root',
'db_password'=>'',
'db'=>'',
'login_enabled'=>true,
'signup_enabled'=>true,
'site_name'=>'Cheesecake Portal',
'b_url'=>'beta.cheesecakebb.org',
'b_email'=>'symbiote#cheesecakeb.org',
'board_enabled'=>true
);
}
// modifiy your settings here searching the key(s) you want to modify
// then put it in the config file
file_put_contents($mySettingsFile, '<?php '.var_export($settings).' ?>');
I hope this will illustrate my idea good enough to help you.
Kohana's config files look like this.. here is an example of a database config file (simplified)
return array(
'dbhost' => 'localhost',
'user' => 'Tom_Jones'
);
I've also got a CMS which wants the connection details. Whilst the CMS uses a different user (with more rights), I'd like to know the best way to include this file and get the data out of it (so as to not repeat myself for hostname and dbname).
I haven't thought up of any elegant solutions yet and have not yet dug around Kohana to see how it does it. It's late Friday here so it's probably really obvious to everyone except me.
Update
My apologies, I forgot to include that this is using Kohana 3!
In Kohana v3, in the Kohana_Config_Reader class, method load():
$config = Arr::merge($config, require $file);
require $file is used to load the array in the configuration file.
I downloaded Kohana and could not files that look like your example, but if you are using the current version you could repurpose the config files like this:
<?php
// Your script
define('SYSPATH', 'true'); // So Kohana doesn't kill our script
$config = array();
include('path/to/system/config/database.php');
echo $config['default']['connection']['user']; // Echos database user
?>
http://docs.php.net/function.include says:
Also, it's possible to return values from included files. You can take the value of the include call as you would a normal function.
Let's take your example code
<?php // test2.php
return array(
'dbhost' => 'localhost',
'user' => 'Tom_Jones'
);
and a script that includes test2.php
<?php
$cfg = include 'test2.php';
if ( !is_array($cfg) ) {
// ... add useful error handling here ...
}
// you might want to test the structure of $cfg
// before accessing specific elements
echo $cfg['dbhost'];
prints localhost.
The documentation contains some basic info on how you access those config files. So if you have the following in a file called db.php in application/config:
<?php defined('SYSPATH') or die('No direct script access.');
return array(
'host' => 'localhost',
'user' => 'Tom_Jones'
);
You'd access them like this:
$options = Kohana::config('db');
echo $options['user'];
echo $options['host'];
Or like this:
echo Kohana::config('db.user');
echo Kohana::config('db.host');
Or like this:
echo Kohana::config('db')->user;
echo Kohana::config('db')->host;