I have a configuration-table(id,name,value), containing some configuration variables for my symfony application such as email_expiration_duration. I want to write a service to read these configuration varibales from symfony application.
I want cache the data in app/cache folder.
That means I will read the data from database only if the data is not in cache.
I will clear the cached data whenever the configuration value changes.
How can I do it in symfony2?
If you want to store this information in a file you manually create in the app/cache folder, you may use the following solution: https://stackoverflow.com/a/13410635/1443490
If you don't want/need to care about what folder is used inside the app/cache folder and your project already uses Doctrine, you can follow this solution: https://stackoverflow.com/a/8900283/1443490
Related
For example, I want to merge two .png files in one .png file, but I don't want to share those parts with user. Currently I am storing files in storage folder, but the problem is that storage folder is with .gitignore file as default. Of course I could allow to push it to git, but I suppose it's not a good idea, because there could be thousands of another files uploaded by the user. Now if I want to continue work from another computer I should move all my parts manually.
So what you could advice to me?
You can store it anywhere you want in your application.
For example, you can make a folder in your projects root called /uploads and then use one of laravel helper functions to specify where to save the file:
Example:
$save_path = base_path('uploads');
You can use the Laravel File Class to make sure the path exists with:
File::makeDirectory($save_path, $mode = 0755, true, true);
You will need to add use File; in the top of the file with all the class includes.
Later, to access said files you can make a View Composer which you can add logic to in order to limit who can view the file.
If you want to protect your files so that nobody can access without permission store all file into storage folder. Don't put your file in public folder.
I'm developing a CRM and i need to access customers database. whole CRM uses mysql to store data. but customers data stored in ms sqlserver.
by default to add another database in codeigniter,it should added from config file. but i want to add it using controller(like cms as wordpress,joomla,etc).
well you cannot update database settings dynamically, as they're loaded long before the controller is initialized.
However, what you could do is, add another set of database config, write into the database.php file using codeigniter file helper using this link.
write_file(APP_PATH.'/config/database.php', $data, 'r+');
Basically you open the file in write mode and set the database config into it.
This is one way of doing it. Just an idea.
Is there a proper explanation as to why when I'm either pulling the complete project from the server, or pushing it on server, views don't get updated? I always have to manually go to the resources folder and transfer views after everything has already uploaded/downloaded.
The solution is to clear your cache like stated in the comments.
php artisan view:clear
The reason why this is happening is because by default the caching is set to File. Which means that the view-cache is stored in files. When you upload everything the old-cache is uploaded. The files are stored in storage\framework\views
If you upload a single folder, laravel notices a change and the cache is busted.
PS: it is recommended that you use git for this kind of stuff, Laravel has .gitignore files to prevent this kind of behavior.
I have some forms that allow the user to upload files that only they can view so I will have to store them somewhere. However, I haven't been able to find any information about where these files would usually be stored if I want them to be kept on the local server. Therefore I have to assume that there is no convention for the permanent storage location of uploaded files. Am I correct in this assumption?
To be clear, I'm not talking about temporary storage locations.
Additionally, would it be a bad idea to have the storage location of all the files as a subfolder of the app directory (with gitignore enabled on it)? Or would it be a better idea to have it outside of the app folder? Thanks!
There is no explicit convention on where to store user uploaded files.
However Laravel ships with a storage directory where it stores framework related data such as cache, sessions, etc. As the name denotes it's a good place to store files, not just framework files. Also the Laravel Filesystem Documentation mentions that the default configured location is storage/app (but that can be changed to fit your needs):
When using the local driver, note that all file operations are relative to the root directory defined in your configuration file. By default, this value is set to the storage/app directory. Therefore, the following method would store a file in storage/app/file.txt: Storage::disk('local')->put('file.txt', 'Contents');
This storage/app folder will by default be ignored by Git.
If you also need the files to be publicly available, then you have two options:
1. Store them somewhere in the public directory.
2. Store them in the storage directory as suggested above and create a symbolic link to the folder from a public location. On Linux you can run this:
ln -s /path/to/laravel/public/files /path/to/laravel/storage/app/files
Of course the directory names can be whatever you like, I used files as an example.
The first option is for cases where you don't have shell access or are otherwise unable to create symbolic links. So if possible I suggest you use the second option.
Laravel uploads to the temporary file path, then you will have to move the file:
$request->file('photo')->move($destinationPath);
This method will move the file from its temporary upload location (as determined by your PHP configuration) to a more permanent destination of your choosing.
SOURCE: https://laravel.com/docs/master/requests#files
I'm using Laravel 5 with CACHE_DRIVER redis.
I found that there are still Views cache files under /storage/framework/views/.
Is it possible to store Views cache in redis? I thought that it will speed up the website.
Thanks!
Laravel 5 doesn't support this. config/view.php is rather stubby and makes no mention of drivers, whereas config/session.php and config/cache.php both have keys that make use of CACHE_DRIVER.
You can store the view cache files in a custom location on the filesystem, but other than that, at time of writing, there's not much else you can do with the views configuration.