Hi everyone i work with cakephp3 and i have implemented the cache from doc
Here is my cache configuration using groups
Cache::config('users', [
'className' => 'File',
'duration' => '+1 hours',
'path' => CACHE,
'serialize' => true,
'groups' => ["users_$groupId"]
]);
And here is my key is created in a folder whose name is the name of the group
Now the prob is when i want to read the key using
Cache::read('my_key')
Doest not work because the key is stored in the folder inside Cache folder
NB: When I haven't used the groups in the cache it works well, I can read my key because the key is stored directly in the cache folder.
Thanks for any help.
You have to specify your custom config when reading from the cache, otherwise the default config will be used, which very likely points to the normal cache folder, hence it "works" when you don't specify any groups in your custom config.
Cache::read('my_key', 'users')
See also
Cookbook > Caching > Reading From a Cache
Cookbook > Caching > Using Groups
Related
I make a disk in filesystem like:
'avatars' => [
'driver' => 'local',
'root' => storage_path('app/avatars')
],
is it possible / how can I ,create a temporary URL for files in this disk?
i tried
return Storage::disk('avatars')->temporaryUrl('pp12.jpeg', now()->addMinutes(5));
but its show me this error:
RuntimeException
This driver does not support creating temporary URLs.
As noted in the documentation, and by the error message, temporary URLs are a feature of the S3 driver, and are not supported on any other driver.
If you don't want to use S3 to store your files (and you should probably consider doing so since it's a cheap and flexible way of hosting large numbers of files), then you will need to add this functionality yourself by creating a custom route that makes the file available for a limited period of time.
There's a number of ways you could achieve this depending on your use case, but I'd suggest looking into JWT - you can generate a JWT that expires after the appropriate time period, include the JWT in the URL as a query parameter, get the token in the route, and use it to prevent access to that route after the token has expired.
Step 1: Add the following code in the AppServiceProvider boot method.
Storage::disk('local')->buildTemporaryUrlsUsing(function ($path, $expiration, $options) {
return URL::temporarySignedRoute(
'local.temp',
$expiration,
array_merge($options, ['path' => $path])
);
});
Step 2: Add the route in web.php
Route::get('local/temp/{path}', function (string $path){
return Storage::disk('local')->download($path);})->name('local.temp');
This will allow downloading of the file using a temporary URL.
Now you can easily generate a temporary URL for the local disk.
disk = Storage::disk('releases-local');
return $disk->temporaryUrl($this->path, now()->addMinutes(5));
I need some help - I want to change the whole design of my website, but I want to have the option to switch back to the old design.
My current folder structure is:
resources/views/frontend/...
I want to have the following folder structure:
resources/views/frontend/v1/...
resources/views/frontend/v2/...
In my config files I want to have a variable version, which will hold the active template version.
The problem is that now I need to use this variable in all Controllers and Views, which is a lot of work. I want to change the variable only in the Views. Does anybody have faced that situation and have a better solution for it ?
If you don't need to be able to switch the theme/design from an admin page, you can simply setup the path to your views in your config/view.php file:
/*
|--------------------------------------------------------------------------
| View Storage Paths
|--------------------------------------------------------------------------
|
| Most templating systems load templates from disk. Here you may specify
| an array of paths that should be checked for your views. Of course
| the usual Laravel view path has already been registered for you.
|
*/
'paths' => [
resource_path('views'),
resource_path('theme/v1/views'),
],
Views in resources/theme/views/ will be loaded as well as the ones in the resources/views directory.
Beware of the order: the first path defined will have a higher priority if two files share the same name.
Another solution, to prevent file name collision, is to use namespaced views. In you AppServiceProvider, add this to the boot() method:
$this->loadViewsFrom(resource_path('theme2/views'), 'theme2');
See https://laravel.com/docs/6.x/packages#views
In both cases, you can use a variable in your configuration. For example, in your config/app.php:
return [
// Leave the configuration and add:
'theme' => 'v1',
];
Then, in config/view.php:
'paths' => [
resource_path('views'),
resource_path('theme/'.config('app.theme').'/views'),
],
If you want to use an environment variable (to have a different theme in local environment and production):
'paths' => [
resource_path('views'),
resource_path('theme/'.env('APP_THEME').'/views'),
],
and in your .env:
APP_THEME=v1
I've found a solution:
I've added namespaces in app\Providers\AppServiceProvider.php, in the boot method:
$this->app['view']->addNamespace('theme', base_path().'/resources/views/frontend/.config('version'));
Than I need in all Controllers and Views make some changes, but this is only one time.
In any Controller I changed from:
return view('frontend.partials.banner')->withBanner($banner);
to:
return view('theme::partials.banner')->withBanner($banner);
and in any view from:
#include('frontend.standing.partials.shorttable')
to:
#include('theme::standing.partials.shorttable')
I want to add a new template option for the product filters block.
So far, I have copied the existing original.tpl from:
templates\blocks\product_filters
and put it into:
templates\addons\my_changes\blocks\product_filters
then I've renamed the file to: example.tpl and edited the top line of the file to be:
{** block-description:example **}
This basic process has worked for other blocks but not for this product filters one. The only options available in the template list are 'Original', and 'Horizontal filters'.
Is there something special I need to do to make my new template show up?
Templates available to be used by blocks are defined at schema, which is located at "app/schemas/block_manager/blocks.php" file.
Usually schema contains a path to a directory containing all templates that can be used by a block, like it's done for the "products" block:
'templates' => 'blocks/products',
Which makes block manager search templates at design/themes/[theme name]/templates/blocks/products directory.
Unfortunately, by some reasons the schema of the "product_filters" block is inconsistent compared to other block schemas - it contains the list of a concrete templates to be used:
'templates' => array(
'blocks/product_filters/original.tpl' => array(),
'blocks/product_filters/selected_filters.tpl' => array(),
'blocks/product_filters/horizontal_filters.tpl' => array(),
),
Because of that, no directory scan is being performed at a moment of determining a list of templates available for a block.
This is why the approach you're using worked for other blocks but not for "product_filters".
The solution for you is simple - you should create a "app/addons/my_changes/schemas/block_manager/blocks.post.php" file with the following content:
<?php
$schema['product_filters']['templates'] = 'blocks/product_filters';
return $schema;
After that please clear the cache and make sure that the "my_changes" add-on is installed and enabled.
Thanks for pointing out this problem, we'll fix it in an upcoming releases.
I've created a couple of pages they are users, groups and permissions.
I would like the admin to be able to create groups and set what those groups can do via the permissions page.
So on the permissions page I would have a list of things a user could do e.g.: add content, delete content.
And if I check the add content box then the group can only add content and not delete content.
The problem I'm having is that I don't know where to go to look for information on how to go about it. I've already got my database set up and I'm thinking maybe sessions and routes is the way to go, but I'm not sure.
Frameworks is the way to go for something this complex. I'm working on a very similar project for my work (a dashboard to do different things based on User Role/Permissions) and I found it incredibly difficult to manage without the use of a framework. I would highly recommend Cartalyst/Sentry for this. It turns complex database operations like checking permissions, update permissions, creating groups etc into simple one. Here is a link to the manual:
Cartalyst/Sentry
It has a database backend already created (and modifiable) for you, so you simply follow the installation instructions and go over the documentation to get a better understanding. In your example, it would be as simple as creating a group and it's permissions:
// Define permissions (1 is allowed, 0 is not allowed)
$permissions = array('content.create' => 1, 'content.delete' => 1, etc etc...));
$group = Sentry::createGroup(array('name' => 'Admin', 'permissions' => $permissions));
Creating a user and adding them to the group:
$user = Sentry::createUser(array('email' => 'test#test.com', 'first_name' => ..., etc));
$group = Sentry::findGroupByName('Admin');
$user->addGroup($group);
And then checking their permissions during routing:
$user = Sentry::check(); // Aka get the current user.
if($user->hasAccess('content.create'){
// Continue
} else {
// Redirect to error page, etc
}
Now that's a brief overview of the system, and I assume you know how to use controllers and routes, but play around with it and I'm sure you'll come to see how powerful this Framework is when working with Laravel.
Hope that helps!
Then checking whether or not a user
How do i remove the Period column from my custom report?
i tried with
unset($this->_columns['period']);
but its not working.
I need to start my columns like order number, order date,subtotal etc etc.
This is loaded by a custom grid of Backend of Magento, you need identify this. To find the custom block you can active backend hints and see what grid are loaded in this section.
You can active backend hints with the next Sql:
UPDATE core_config_data SET scope_id = 0 WHERE path like 'dev/debug/template_hints%';
Execute always in development enviroment. Never in production site
You can see how to active backend hints in this link, http://www.damianculotta.com.ar/2009/07/11/mostrar-phtmls-y-bloques-usados-en-el-skin-de-backend-de-magento/ sorry, this is in spanish, I don´t find this information in english :(
With this you also to know the type of block load in this grid, this is the important date. Next you need create a little module that rewrite this block.
Whit this method you can see that the next dates
Template
adminhtml\default\default\template\widget/grid.phtml
Block
Mage_Adminhtml_Block_Report_Sales_Sales_Grid
in the block you can see the next columm in the construct
$this->addColumn('period', array(
'header' => Mage::helper('sales')->__('Period'),
'index' => 'period',
'width' => 100,
'sortable' => false,
'period_type' => $this->getPeriodType(),
'renderer' => 'adminhtml/report_sales_grid_column_renderer_date',
'totals_label' => Mage::helper('sales')->__('Total'),
'html_decorators' => array('nobr'),
));
You need remove this columm in you custom block, always in separate extension.
If you don´t know how you can rewrite a block, only need said me :P
Hope help you