This extension is an alternative to my "myconfig" extension from here: http://www.yiiframework.com/extension/myconfig/ but it uses only the database+caching.
As explained in this comment http://www.yiiframework.com/extension/myconfig/#c3727 using this extension has some advantages and some extra requirements.
Requirements ¶
1) Yii 1.1.x
2) A Cache component activated (CFileCache will do it just fine)
Instalation ¶
Add the component to the main.php config file:
[...]
'cache'=>array(
'class'=>'system.caching.CFileCache',
),
'settings'=>array(
'class' => 'CmsSettings',
'cacheComponentId' => 'cache',
'cacheId' => 'global_website_settings',
'cacheTime' => 84000,
'tableName' => '{{settings}}',
'dbComponentId' => 'db',
'createTable' => true,
'dbEngine' => 'InnoDB',
),
[...]
Usage ¶
/*
* Set a database item:
* $itemName can be an associative array() in key=>value pairs ($itemValue="" in this case)
*/
Yii::app()->settings->set($categoryName, $itemName, $itemValue, $toDatabase=true);
// Get a database item:
Yii::app()->settings->get($categoryName, $itemName);
// Get all items from a category:
Yii::app()->settings->get($categoryName);
// Delete a database item:
Yii::app()->settings->delete($categoryName, $itemName);
// Delete all items from a category:
Yii::app()->settings->delete($categoryName);
//Import items from a file:
$items=include('path/to/file.php');//returns an array() in key=>value pairs
Yii::app()->settings->set($categoryName, $items);
The component uses something like "lazy loading" for loading items within a category, meaning that the items from a category will be loaded when you request them first time. Beside this, at the end of the request, the items from that requested category are written to cache, so next time when you request them, they will be served from cache.
Note, the component is smart enough to know itself when a new item/category has been added and refresh the cache accordingly so you don't have to keep track of the items you add to database.
Basically, in most of the cases, the database will be hit only once, then all items will be served from cache, which means you will get a nice way to manage the project configuration without performance penalties.
Notes & Changelog ¶
Version 1.1.c
Various improvements
Version 1.1.d
-> Contains small performance improvements.
-> You can now use the get() method like
$retrieve_custom_settings=Yii::app()->settings->get('system',array('admin_email','contact_email','my_email'=>'some default value'));
In the above example, $retrieve_custom_settings becomes an array having the 'admin_email' and 'contact_email' keys. If these values are empty or they don't exists in database then they will be set to null otherwise you will retrieve their values. It is set this way so that you can safely use $retrieve_custom_settings['admin_email'] even if it doesn't exists.
Version 1.1.e
->Added setters/getters for all the public properties.
->The component supports the automatic creation of the database table (optionally, you can specify which storage engine to use in case you use MYSQL)
->Added the option to specify the name of the Cache/Database components via the $cacheComponentId and $dbComponentId properties.
->removed the __call() magic function.
->commented the class methods.
Special thanks goes to Gustavo who helped me allot with this version.
Upgrading to this version will not break the backward compatibility in any way(hope you didn't make use of the __call() method) and it is recommended to do so.
In case you use the autocreate database table option, don't forget to turn it off after the table has been created.
Version 1.2
-> added the deleteCache() public method to allow to delete cached categories
-> implemented a cache registry that will hold all the cached categories and it will be updated
each time a new category is loaded/deleted
Usage:
-> various changes that won't break BC.
Yii::app()->settings->deleteCache('categoryName'); //delete a single category
Yii::app()->settings->deleteCache(array('c1', 'c2','c3')); // delete multiple categories
Yii::app()->settings->deleteCache(); // delete all cached categories.
Please let me know in case you find any error.
hehe :) that 's my need! thank you my friend.
i left some message for asking this extension
( http://www.yiiframework.com/extension/myconfig/#c3932) ,
so thank you very much for sharing this ext .
cheers !
No problem
You're welcome :)
@twisted1919: some error happens
CDbException
CDbCommand 无法执行 SQL 语句: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '{settings}} WHERE
category
='hello' ANDkey
='world' LIMIT 1' at line 1. The SQL statement executed was: SELECT * FROM {{settings}} WHEREcategory
=:cat ANDkey
=:key LIMIT 1the test code i use :
Yii::app()->cfg->set('hello','world','test',true); echo Yii::app()->cfg->get("hello",'world');
$connection=Yii::app()->db;
218 $command=$connection->createCommand('SELECT * FROM {{settings}} WHERE
category
=:cat ANDkey
=:key LIMIT 1');219 $command->bindParam(':cat',$category,PDO::PARAM_STR);
220 $command->bindParam(':key',$key,PDO::PARAM_STR);
221 $result=$command->queryRow(); <<--------- this line throw exception
well
you don't have to pass the boolean: true as the fourth param of the set() method. it is set to true by default, so :
Yii::app()->cfg->set('hello','world','test');
You created the database table, right ? the one posted in this component ?
What's your yii version ? if it isn't 1.1.7, can you test on 1.1.7 ?
Can you post the config part of the component from your main.php file ?
You did something wrong, that's for sure, but i cannot say for sure what till you answer the above questions .
may be some strange charset reason,or some symbol?
i test it in mysql ,and yii 1.1.7. just follow the above doc. :)
hehe
well, i believe i know what the problem is.
You will notice that the table name is like {{settings}} this means, the database component definition has set a database table prefix, which in my case is cms_ .
You can try do following:
1) In your db component, add a new param, like:
'db'=>array(
[...]
'tablePrefix' => '',
[...]
),
2) If you're not using a table prefix or the above code won't work, just do a search and replace all of the "{{settings}}" with "settings" in the component class.
Sorry, for this issue, is just this class is part of my own CMS and it is adjusted to work with it. I shared this just because you asked to :)
@twisted1919 yes i created the table as you give in the source code .
i read the code , and know every param usage,:)
so may be i can debug it myself :) , it 's too late for me . may be tomorrow i will do it , it's midnight here .
suggestion: never use the db keywords like 'key' as column name ,
and you can adopt the $categoryName to back: public function get($category='system', $key='', $default='') ---->to public function get( $key='', $default='',$category='system'); setter function is same,and others too.....
thus there is a default cate 'system', assign to another value only when necessary. and can keep the same config set/get access way as another config ext set/getter style (myConfig econfig etc....) best wishes!
@ twisted1919 yes it works now
you are right ! that is the tablePrefix reason. and thanks again for your share . if you can detected it in the your ext.
cheers and good night ! hehheeee :)
yup
yup, i was sure that is the reason:)
Weird problem
Hi,
I am testing on this component, and i found it seems we cannot set and get different variable at same page/file, it return null after all.
e.g.
i have 3 configurations set into database.
1st, cat: "admin", key: "email", value: s:18:"test@email.com";
2nd, cat: "admin", key: "phone", value: i:123256;
3rd, cat: "admin", key: "data", value: O:9:"MyObjects" ..... (raw object text);
in the same page, i code like this:
Yii::app()->settings->set('admin','email','admin@jobpoint.com'); //Yii::app()->settings->set('admin','phone',123256); $phone = Yii::app()->settings->get('admin','phone'); var_dump($phone);//it is null $data= Yii::app()->settings->get('admin','data'); var_dump($data);//it is also null
but if like this, then the phone have value of interger 123256
//Yii::app()->settings->set('admin','email','admin@jobpoint.com'); Yii::app()->settings->set('admin','phone',123256); $phone = Yii::app()->settings->get('admin','phone'); var_dump($phone);//interger: 123256 $data= Yii::app()->settings->get('admin','data'); var_dump($data);//it is also null
notes: those 3 values already in the databases. (set before testing.)
Will fix it.
I know what the problem is ;)
I will fix it asap and will update the extension.
please test
@ ryurhrt - Please download and test the 1.1 version. The bug you described should be fixed now.
Let me know the result.
Thanks.
add a Description field for the individual settings
Thank you for your great work. We would like to ask you to add a
description
field where we can enter text that will be displayed on the admin screen, and will describe the usage.is it really needed?
Well, is the description field really needed ?
I mean, if you have a category named admin, and you have two fields, say phone and email,
if you want description for these, you can do something like:
$data=array( 'phone' => '0123456789', 'email' => 'admin@domain.com', 'desc_phone'=> 'this is the phone number of the administrator', 'desc_email'=> 'this is the email address of the administrator', ); Yii::app()->settings->set('admin',$data); // $phone=Yii::app()->settings->get('admin','phone'); $phone_desc=Yii::app()->settings->get('admin','desc_phone'); echo $phone.' - '.$phone_desc;
You get the point here, right ?
I don't see a performance issue doing like this, i mean, the data is cached anyway, and not every item has a description(ie: i have a lot of items used internally, no description needed) that's why i believe it is better this way.
If you have something to add, please do :)
Another way.
Another way, would be like:
$data=array( 'phone' => array( 'value' =>'0123456789', 'description'=>'this is the phone number of the administrator', ), 'email' => array( 'value' =>'admin@domain.com', 'description'=>'this is the email address of the administrator', ) ); Yii::app()->settings->set('admin',$data); // $phone=Yii::app()->settings->get('admin','phone'); echo $phone['value'].' - '.$phone['description'];
As you see, we have some alternatives :)
cool that I can save complex objects too
It is nice that I can save complex data. But the descriptions I am refering would be set/retrieved rarely when the administrator edits in the CMS admin. The descriptions are used only for the admins and would describe what each value means, not used by the read/write mechanism. It would be too complex to store each value as an associative array, and have a
value
and adescription
field each time. It would make things harder when you need to display a value from the associative array. Is it clear thedescription
requirement?i understood
I understood your requirement since first time, don't worry.
The thing is that, integrating this will make the component heavier, thing i don't want right now, i want to keep this as light as possible.
And yes, i agree with you that doing this in one of the way i shown you can be a bit hard with large sets of data, but it is doable, so for now, you'd have to work with it as it is.
In my projects, where the items need description, i use one of the two methods i shown, and i have no problems.
Of course, there is always the second option, modify the component to fit your needs, nobody says you cannot do this :)
Testing result
@twisted1919
I had tested, I guess the bug is now fixed.
However, I am not so sure about it, because the 1st time when I run the test, it return a Boolean "false" for me, but once after I refresh it, it works without any problem, and I could not repeat the fault.
anyway, well done. Thanks. :D
is it a bugs?
Hi, i finally repeated the bugs which return "false" value.
the bugs is occur in another testing server where the server do not call any "set" function yet, as all the settings had been called and saved using my development, so no matter how many times we called "get" function, the value return is "false", but after run at least once the "set" function, then all the "get" function works.
i would guess it happen because of caching not yet initialized? any idea to resolve this issue beside calling set function every time server reboot or implement to new machine?
Thanks.
let's try something else
@ryurhrt - thanks for your tests, i also appreciate your time .
Let's test a few things and see where we go next:
1) Change the get method like:
// line 49 public function get($category='system', $key='', $default='') { if(!isset($this->_items[$category])) { $this->load($category); } if(!isset($this->_loaded[$category])) { $this->load($category); $this->_items[$category]=array_merge($this->_loaded[$category],$this->_items[$category]); } if(empty($key)&&empty($default)&&!empty($category)) return isset($this->_items[$category])?$this->_items[$category]:null; if(isset($this->_items[$category][$key])) return $this->_items[$category][$key]; return !empty($default)?$default:null; }
After doing the change, test it and see if the bug still persists, if it does, then let's do a more direct approach to the get function:
// line 49 public function get($category='system', $key='', $default='') { if(!isset($this->_loaded[$category])) { $this->load($category); $this->_items[$category]=array_merge($this->_loaded[$category],$this->_items[$category]); } if(empty($key)&&empty($default)&&!empty($category)) return isset($this->_items[$category])?$this->_items[$category]:null; if(isset($this->_items[$category][$key])) return $this->_items[$category][$key]; return !empty($default)?$default:null; }
Also, what i would ask you to do in your tests, is to clear the cache folder before you do each test, because when you move the project to a new site the old cache might be invalidated and the tests will not be accurate.
So, clear the cache, run the test, see the restult, and repeat the steps each time.
Please let me know of your findings so that i can update the component if indeed what you just explained is a bug :)
Thank you for your time on this .
Try this
Please ignore my above PHP code (not the cache advices) and try this version, just overwrite the component class with this one :
Paste Bin Code
Another Problem Happen
Hi,
after tested the new code, i found that i can't set the settings, which means at the same page, i do set the value to another, but the get back the old value.
any idea?
i see no issue, please share code.
Well, i cannot reproduce what you are saying, at least here is the test i made:
$settings=Yii::app()->settings; echo $settings->get('test','itemAlreadySet').'<br />'; $settings->set('test','aNewItem','aNewValue'); echo $settings->get('test','aNewItem').'<br />'; $settings->set('test','aNewItem','aNewValueOverwritten'); echo $settings->get('test','aNewItem').'<br />'; $settings->set('test','itemAlreadySet','rewrite this value'); echo $settings->get('test','itemAlreadySet').'<br />';
And the output of the above code:
Which seems correct to me.
Next step was just to retrieve the values i just set above:
$settings=Yii::app()->settings; echo $settings->get('test','itemAlreadySet').'<br />'; echo $settings->get('test','aNewItem').'<br />';
Which outputs:
So, once again, it is correct.
As you see, the code works exaclty as expected, that's the reason why i can't find any error.
I will gladly look into your issue, but please post some code so that i can run it in my backend and see if it fails or not.
Ops.. sorry.
Hi,
Sorry for the false bugs report, as I actually code to read the configuration with a class of my own, and i forgot the switch the reading class to read from the settings, and it read back to the yii's settings, so even i reset the value, it still reading the wrong place.
sorry for that, but now the module work correctly without any problem, thanks.
great.
Good to hear, but don't worry, thanks to you the extension has been improved and some bugs were fixed, so you did a great job reporting all of these.
need enhance some features !
@twisted1919 : I am here again :)
now my situation is this: the table your provided is different from mine. but the
table fields have same semantics , only i need is tableName and table fields mapping.
so i need something like this:
public $tableName = 'settings'; /*default name is your name for those guys who firstly use this setting feature,and use your schema above .*/ public $idAttribute='id'; public $categoryAttribute='category'; public $keyAttribute='key'; public $valueAttribute='value';
then in your code reference above values: {$this->tableName} , {$this->xxAttibute} , thus these extension can apply to the tables existing early ,
surely i can do it myself ,but if you can add it will be better :).
best regards !
Empty string bug
@twisted1919 I encountered the same bug as ryurhrt
After looking trough the code, I found what the problem is:
In the load() function you unserialize every corresponding key value from the database. If the value is a string then the function returns false as it is unserializeable.
To fix it, simply replace:
foreach($result AS $row) $items[$row['key']] = @unserialize($row['value']);
with
foreach($result AS $row) { $value = @unserialize($row['value']); if ($value === false) $value = $row['value']; $items[$row['key']] = $value; }
Empty string bug
@twisted1919 It seems the problem I had was due to the fact that I inserted the values by hand in the db (using phpmyadmin) instead of using the functions provided by the extension, which serialize the values before saving them to the db. Sorry about that.
Hi there
Just now i saw the comments, don't know why but the yii website doesn't send notifications anymore for comments on my extensions.
@Wiseon3 - the values shouldn't be manipulated directly from database. And i prefer to use the serialize/unserialize functions to store all kind of data in the database.
Anyway, glad to hear this isn't another bug:)
@yiqing95 - sorry, right now i don't have too much available time, but i will take it into consideration.
forum post
please create a post to discuss about the extension.
I've made a modified version of the extension that I would like to share.
Basically what I've changed is that I added a public property named 'tableName' with default value '{{settings}}' so you can easiely change the name of the table to use and this change also removes the need to add tablePrefix if you don't use it.
I've also added a connectionId property that defaults to 'db' and a getDbConnection method, replacing all Yii::app()->db to $this->getDbConnection so you can use a different db connection.
And a couple more things
Btw, great extension.
Thanks
Topic created
I opened a new topic here: http://www.yiiframework.com/forum/index.php?/topic/23075-extensionsettings/ , please add the file as an attachment there and i'll check it and in the end implement your changes.
How to clear cache?
Can we have a method where clear the cache for all groups? (I have a migration that inserts some values into the settings table, and I would like to call a method after that to clear the cache.)
Clear cache
This would require to have some kind of registry to store permanently all the defined categories that are cached, and it might be a good thing to have something like:
Yii::app()->settings->clearCache(); //clear all the cached content Yii::app()->settings->clearCache('category'); // clear only this category cache.
So i'll take it into consideration and implement it :)
Component updated.
The component has been updated to version 1.2 with some new goodies (see changelog)
Please test it and report any bug you find.
Thanks.
table name format
I had to remove the {{ }} around the table name param (in config file or in the default param value. To get it to work.
Otherwise it raise an exception :
CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '{settings}} WHERE `category`='bidon' AND `key`='appname' LIMIT 1' at line 1. The SQL statement executed was: SELECT id FROM {{settings}} WHERE `category`=:cat AND `key`=:key LIMIT 1 .../yii/framework/db/CDbCommand.php(528)
Then it seems to work ok (not tested a lot).
2012-06-01 17:24:39 Apache/2.2.21 (FreeBSD) mod_ssl/2.2.21 OpenSSL/0.9.8q PHP/5.3.8 with Suhosin-Patch Yii Framework/1.1.10
db design
I'm not a db expert, but it looks like the database table field 'id' is not used for insert/update/delete operation, so the primary key (id) of that table is not used. It could be better to have a composite primary key ('category','key').
database table prefix
it was written somewhere here that your database settings should also include a database table prefix even if it is just an empty string .
table name format
Ok, i don't use prefix.
I suggest writing it to the extension description text, because i hav'nt read all the comments (but maybe i'm the only one not reading all comments).
Sorry.
(Feel free to delete that comment and the previous one (if you can))
Options to set table column names and default category name
Back to comment #4225
Nothing new, just new options.
Question to author: Where to send the updated code, if possibly?
Or maybe I do fork on github?
protected $_dbComponentId='db'; protected $_tableName='{{settings}}'; protected $_idColumn='id'; protected $_categoryColumn='category'; protected $_keyColumn='key'; protected $_valueColumn='value'; protected $_createTable=false; protected $_dbEngine='InnoDB'; protected $_defaultCategory='system'; ....... ....... protected function createTable() { $connection=$this->getDbComponent(); $tableName=$connection->tablePrefix.str_replace(array('{{','}}'), '', $this->getTableName()); $sql='CREATE TABLE IF NOT EXISTS `'.$tableName.'` ( `'.$this->_idColumn.'` int(11) NOT NULL auto_increment, `'.$this->_categoryColumn.'` varchar(64) NOT NULL default \''.$this->_defaultCategory.'\', `'.$this->_keyColumn.'` varchar(255) NOT NULL, `'.$this->_valueColumn.'` text NOT NULL, PRIMARY KEY (`'.$this->_idColumn.'`), KEY `'.$this->_categoryColumn.'_key` (`'.$this->_categoryColumn.'`,`'.$this->_keyColumn.'`) ) '.($this->getDbEngine() ? 'ENGINE='.$this->getDbEngine() : '').' DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; '; $command=$connection->createCommand($sql); $command->execute(); }
will do
@fad
okay, this will be implemented in the next version (along with a few bug fixes) which will be available somewhere this week.
Change createTable to Yii style
Hi, after using your settings for a long time, I see some minor fix should be made:
protected function createTable() { $schema = Yii::app()->getDb()->getSchema(); $table = $schema->quoteTableName($this->getTableName()); $create = $schema->createTable( $table, array( 'category' => 'string', 'key' => 'string', 'value' => 'text', ) ); $index = $schema->createIndex('category_key', $table, 'category,key', TRUE); Yii::app()->getDb()->createCommand($create)->execute(); Yii::app()->getDb()->createCommand($index)->execute(); return TRUE; }
This will use Yii createTable instead of raw SQL one.
I think this is more convenient, in case switching db engine.
Also, remove the dbEngine variable, and table prefix. No need for that, right?
Approach to usage with many parameters
Hi to all,
This extension is very useful and I use it in several projects. From my experience, when application has a lot of different parameters, it may become not handy to manage them.
With following approach I'm trying to solve such hassles:
1) a lot of editions when you need to add new parameters to your application
2) obtrusive (not handy) code in model, controller and view files (which I first met on a large project where this extension was used)
3) instead of writing long requests, to use small helper function to call parameters
What can be improved:
1) add proper validation method (which isn't difficult to add, I just didn't need it for now)
2) get rid of literals usage as categories and parameters names - I think it would be more handy to have kinda of constants.
Your suggestions are welcome :)
controller
class SettingsController extends Controller { public function actionIndex() { $settings = app()->settings; $model = new SettingsForm(); if (isset($_POST['SettingsForm'])) { $model->setAttributes($_POST['SettingsForm']); $settings->deleteCache(); foreach($model->attributes as $category => $values){ $settings->set($category, $values); } user()->setFlash('success', 'Site settings were updated.'); $this->refresh(); } foreach($model->attributes as $category => $values){ $cat = $model->$category; foreach($values as $key=>$val){ $cat[$key] = $settings->get($category, $key); } $model->$category = $cat; } $this->render('index', array('model' => $model)); } }
model
class SettingsForm extends CFormModel { public $site = array( 'name' => '', 'googleAPIKey' => '', 'numSearchResults' => '', 'defaultLanguage' => '', 'defaultCurrency' => '', ); public $seo = array( 'mainTitle' => '', 'mainKwrds' => '', 'mainDescr' => '' ); public $mail = array( 'adminEmail' => '', 'fromReply' => '', 'fromNoReply' => '', 'server' => '', 'port' => '', 'user' => '', 'password' => '', 'ssl' => '', ); public $filter = array( 'priceLower'=>'', 'priceUpper'=>'', ); /** * Declares customized attribute labels. * If not declared here, an attribute would have a label that is * the same as its name with the first letter in upper case. */ public function getAttributesLabels($key) { $keys = array( 'googleAPIKey' => 'Google API Key', 'numSearchResults' => 'Number of search results at one page', 'mainTitle' => 'Main Page Title', 'mainKwrds' => 'Default Keywords (Meta Tag)', 'mainDescr' => 'Default Description (Meta Tag)', ); if(array_key_exists($key, $keys)) return $keys[$key]; $label = trim(strtolower(str_replace(array('-', '_'), ' ', preg_replace('/(?<![A-Z])[A-Z]/', ' \0', $key)))); $label = preg_replace('/\s+/', ' ', $label); if (strcasecmp(substr($label, -3), ' id') === 0) $label = substr($label, 0, -3); return ucwords($label); } /** * Sets attribues values * @param array $values * @param boolean $safeOnly */ public function setAttributes($values,$safeOnly=true) { if(!is_array($values)) return; foreach($values as $category=>$values) { if(isset($this->$category)) { $cat = $this->$category; foreach ($values as $key => $value) { if(isset($cat[$key])){ $cat[$key] = $value; } } $this->$category = $cat; } } } }
views to set params
main view shows tabs, content for which is stored in partial views
index.php
<h3>Site Settings</h3> <?php echo CHtml::errorSummary($model); ?> <?php echo CHtml::beginForm(); ?> <ul class="nav nav-tabs" id="site-settings"> <?php $tabs = array(); $i = 0; foreach ($model->attributes as $category => $values):?> <li<?php echo !$i?' class="active"':''?>><a href="#<?php echo $category?>" data-toggle="tab"><?php echo ucfirst($category)?></a></li> <?php $i ++; endforeach;?> </ul> <div class="tab-content"> <?php $i = 0; foreach ($model->attributes as $category => $values):?> <div class="tab-pane<?php echo !$i?' active':''?>" id="<?php echo $category?>"> <?php $this->renderPartial( '_'.$category, array('model' => $model, 'values' => $values, 'category' => $category) ); ?> </div> <?php $i ++; endforeach;?> </div> <?php echo CHtml::submitButton('Submit', array('class' => 'btn')); echo CHtml::endForm();
example partial view
<?php foreach ($values as $key => $val): ?> <div class="control-group"> <?php echo CHtml::label($model->getAttributesLabels($key), $key); ?> <?php if($key === 'ssl') echo CHtml::checkBox(get_class($model) . '[' . $category . '][' . $key . ']', $val); else echo CHtml::textField(get_class($model) . '[' . $category . '][' . $key . ']', $val, array('class'=>'input-xxlarge')); ?> <?php echo CHtml::error($model, $category); ?> </div> <?php endforeach; ?>
catch parameter
Helper function is stored in globals.php, which may be included to code in application bootstrap file.
/** * Shortcut for Yii::app()->settings->get(); * @param string $param */ function sg($category, $key){ return Yii::app()->settings->get($category, $key); }
usage
sg('site', 'name');
P.S. I would put this message to extension forum topic but couldn't find the link to it here.
Sorry, but not enough time right now :(
Hi all, i read all your comments but for now i don't really have enough time to implement everything as i am very busy at work. Hope i'll have some spare time to improve the extension in the near future(the version used in my projects already is better, so i'll post all at once).
Thanks for your pacience:)
database
HI, but the table {{settings}} it dynamically creates or is to be created manually? I see, dynamically ... and the fields manually right ?
tableprefix issue
Hi, in the config must point out that you do not want to make use of the prefix
'db'=>array( 'connectionString' => 'mysql:host=localhost;dbname=dbname', 'emulatePrepare' => true, 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'tablePrefix' => '', ),
any play for yii2
this is a great extension . so it 's meaningful to rewriting for yii2 .
Database access
It seems its a realy good extension, but does it work with postgresql database? I tried to use it, but a lot of errors comes up depending on the components code.
Do you have time to upgrade settings to Yii2 version? Thanks.
This is a good widget.
Do you have time to upgrade it to Yii2 version?
Thanks.
WARNING WITH TRANSACTIONS
Something to keep in mind when use this extension , be very careful when you use transactions, ROLLBACK doesn' t work . I realized this after several hours to detect the inconsistency , please Documentation should warn of this, we would save much time.
In fact you must put the value False in te parameter 'createTable'
'createTable' => false,
In your config/main FILE
So you avoid troubles with ROLLBACK sentences
Yii 2 - Settings
Hi,
As I've jumped from Yii to Yii 2 now, I decided to rewrite this extension for Yii 2.
You can find it here -> https://packagist.org/packages/marsoltys/yii2-settings
I've hope you will find it usefull.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.