I have the following code:
$cell = $this->cell('Admin/Notifications', ['since' => $user['last_login']], [
'cache' => ['config' => 'cell_cache', 'key' => 'notifications_' . $user['id']]
]);
echo $cell;
That i use to call a cell in CakePHP 3 and cache it at the same time. But it outputs an error:
Warning (512): Could not render cell - The "cell_cache" cache configuration does not exist. [CORE\src\View\Cell.php, line 244]
What am I missing? I have searched the manual but have not found if i must declare this configuration and where.
Thank you up front for your answers.
I have found the answer. In "config/app.php" I have added the following code to the "Cache" adapters:
'cell_cache' => [
'className' => 'File',
'prefix' => 'myapp_cell_cache_',
'path' => CACHE . 'persistent/',
'serialize' => true,
'duration' => '+10 minutes',
],
So it was something I have missed to configure, but it is not specified in the docs. I think it should be added.
Related
Hello everyone I work with cakephp3 here is my cache configuration in app.php
'Cache' => [
'access_token' => [
'className' => 'File',
'duration' => '+2 minutes',
'path' => CACHE
]
],
I set the duration to 2 minutes but I need to dynamically change the duration via my Controller.
I I tried setConfig but it does not work
Cache::write("access_token_$key", $response, 'access_token');
Cache::setConfig("access_token_$key", array('duration' => $time));
Also i tried this but still does not work
$engine = Cache::engine("access_token_$key");
$engine->config("duration", $time);
Thanks for any help
I am implementing page cache for one of my page. For depenedency, I have to check an array, which can be either exist or not. Possible array keys cane ,
usersearch['id'], usersearch['name'], usersearch['phone]. I have to add dependency for any change in these values as well.
Also, I have to clear cache for any update or add in user table.
Is there any possible solution for this.?
Thanks in advance
You can use variations
public function behaviors(){
$usersearch = Yii::$app->requst->get('usersearch');
return [
[
'class' => 'yii\filters\PageCache',
'only' => ['index'],
'duration' => 60,
'variations' => [
'YOUR_DYNAMIC_VALUE1','YOUR_DYNAMIC_VALUE2'
],
'dependency' => [
'class' => 'yii\caching\DbDependency',
'sql' => 'SELECT COUNT(*) FROM post',
],
],
];
}
Ref link
IN YOUR CASE ,you can use
'variations' => \Yii::$app->requst->get('usersearch')??[],
or
'variations' => [
\/Yii::$app->requst->get('usersearch')['id'] ?? '',
\Yii::$app->requst->get('usersearch')['name'] ?? '',
\Yii::$app->requst->get('usersearch')['phone'] ?? '',
]
You could use a yii\caching\FileCache component with the following configuration.
Firstly, you set the cache in the init function of your controller:
Yii::$app->setComponents([
'yourCacheName' => [
'class' => \yii\caching\FileCache::class,
'defaultDuration' => 1800, //cache duration in seconds
'keyPrefix' => Yii::$app->getSession()->getId(). '_'
]
]);
Here, the parameter keyPrefix is set so that it is linked to the session ID. Thus, the visitors do not see each other's cached page. If the content is static and equal, regardless of the user or the session, this parameter can be removed.
In the view that must be cached you can call the beginCache function and the dependency as follows:
$this->beginCache('cache-id', [
'cache' => Yii::$app->yourCacheName, // the name of the component as set before
'variations' => [
$usersearch['id'] ?? '',
$usersearch['name'] ?? '',
$usersearch['phone'] ?? '',
],
'dependency' => [
'class' => \yii\caching\DbDependency::class,
'sql' => 'SELECT count(*) FROM your_user_table'
]
]);
// your view
$this->endCache();
I am adding attribute by updating sql script, like this,
$installer = $this;
$installer->startSetup();
$installer->addAttribute('customer_address', 'group_id', array(
'label' => 'Address group',
'visible' => true,
'required' => false,
'type' => 'int',
'input' => 'select',
'source' => 'address_group/address_attribute_source_group',
'user_defined' => 1,
'position' => 100
));
.
.
.
$installer->endSetup();
I am unable to understand what is meant by following line, I am unable to find any explanation about it
'source' => 'address_group/address_attribute_source_group',
I am unable to comment on your post. Trying to understand if you have copied this code from somewhere. From your code I understand that you want to add a "Customer Address Attribute" named as "customer_address"
'source' => 'address_group/address_attribute_source_group'
The implication of the above is the path. You should have a folder/file path as below:
/app/code/local/Address/Group/Model/Address/Attribute/Source/Group.php
Group.php:
class Address_Group_Model_Address_Attribute_Source_Group ...
Since, this attribute is of TYPE => "SELECT", you should be having the options array in this file "Group.php"
Options Array should be something very similar to:
public function toOptionsArray() {
return array(
array(
'label' => '',
'value' => ''
),
array(
'label' => Yes,
'value' => 1
),
array(
'label' => No,
'value' => 0
)
);
}
Let me know if you got it!
Happy to Help!
Happy Coding...
It points to the class that provides options for the attribute. As attribute uses select input it requires options to be provided. This class is created by calling Mage::getModel() and passing the value of source to it. To find the class you need to find node models/address_group in config.xml files of the available modules. This will provide class prefix. Next what comes after slash is added to that prefix in order to create class name. So in this case it will resolve to something like Company_AddressGroupModule_Model_Address_Attribute_Source_Group. This class need to implement toOptionsArray method that returns an array in the following format:
array(
array('value' => 'option_value', 'label' => 'option_label'),
...
);
How to call config item from config file for view in codeigniter.
here is my config file
$config['user'] = array(
'email_validation' => 'email validation',///^([\w-]+(?:\.[\w-]+)*)#((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
'no_permission' => '/',
'admin_group' => 'admin',
'default_group' => 'default',
'public_group' => 'public',
'users' => 'aauth_users',
'groups' => 'aauth_groups',
'user_to_group' => 'aauth_user_to_group',
'perms' => 'aauth_perms',
'perm_to_group' => 'aauth_perm_to_group',
'perm_to_user' => 'aauth_perm_to_user',
'pms' => 'aauth_pms',
'system_variables' => 'aauth_system_variables',
'user_variables' => 'aauth_user_variables',
'remember' => ' +3 days',
'max' => 13,
'valid_chars' => array(' ', '\''),
'ddos_protection' => true,
'recaptcha_active' => false,
'recaptcha_login_attempts' => 4,
'recaptcha_siteKey' => '',
'recaptcha_secret' => '',
'max_login_attempt' => 10,
'verification' => false,
'email' => 'admin#admin.com',
'name' => 'Emre Akay'
);
Here is my load config
$this->config->load('user');
And I will view its item for view as below
$site_name = $this->config->item('email_validation');
But is don't show any thing
This is because your config array is two dimensional array. So, you can't access directly email_validation without getting user first. Moreover,
$this->config->load('user'); just means loading user.php from application/config/ directory. Doesn't mean loading user index from $config array. You can do it like that.
$userConfig = $this->config->item('user');
echo $userConfig["email_validation"];
Edit
Please make sure you config file is under application/config/ and loaded.
$this->config->load('user');
You can check which config is loaded by doing like this.
echo "<pre>";
print_r($this->config);
echo "</pre>";
Hope it will be useful for you.
if your php version>=5.4 you can use this
$site_name = $this->config->item('user')['email_validation']
I am using elFinder 2 + Codeigniter. And I would like to restrict users from deleting or modifying the existing files on all my folders.
I tried with this:
function elfinder_init(){
$this->load->helper('path');
$opts = array(
// 'debug' => true,
'roots' => array(
array(
'driver' => 'LocalFileSystem',
'path' => set_realpath('root'),
'URL' => base_url('root'),
//This didn't do the trick***
'defaults' => array('read' => true, 'write' => false, 'locked' => true),
)
)
);
$this->load->library('elfinder_lib', $opts);
}
It prevent users from uploading new files, but still allows them to modify/delete the existing ones.
Official documentation there is very vague in general and there is no info on how to achieve this, so if you could help me, I'll really appreciate it.
Extracted from their own GitHub issues tickets :
Here is an example to lock folder and subfolder write / delete
array(
'pattern' => '/.(lockedFolder1|lockedFolder2)/',
// Dont write or delete to this and all subfolders
'read' => true,
'write' => false,
'locked' => true
)
Here is an example to lock root but not subfolders :
array(
'pattern' => '/.(lockedFolder1|lockedFolder2)$/',
// Dont write or delete to this but subfolders and files
'read' => true,
'write' => false,
'locked' => true
)
Source