Okay, data processing is complete. now we only need to call the relevant data in views/main. php. The keyword is used as an example.
1. create a table structure
?
123456 |
Create table if not exists 'config' ('name' varchar (128) not null, 'value' varchar (128) not null, KEY 'name' ('name '), KEY 'value' ('value') ENGINE = MyISAM default charset = utf8 COMMENT = 'site info table '; |
First, we need to explain that because the website name, keyword, and other information are a single call, we do not need to create a primary key or auto-increment ID, as long as we do the two-dimensional assembly during storage or extraction. The following is an example!
2. configure memcache
Because Yii can configure multiple cache instances, it is very convenient to call. if one of the configurations is memcache, we only need Yii: app () -> memcache-> set ($ key, $ value );
Configure the instance config/main. php
?
123456789101112 |
'Components' => array ('memcache' => array ('class' => 'cmcache', 'servers' => array ('host' => '123. 0.0.1 ', 'port' => 11211, 'weight' => 60 ,),),),), |
3. configure full-site call
How can I configure full-site calls? Because each Controller inherits components/Controller, we can configure a global array attribute here to call this attribute anywhere on the entire site!
Create Public attributes
?
1 |
Public $ global = array (); |
Attribute value
?
1234 |
Publicfunctioninit () {$ this-> global = $ this-> setKey ();} |
Assemble an array?
1234567891011121314 |
PrivatefunctionsetKey () {if (! Yii: app ()-> memcache-> get ('keyword') {$ cache = Config: model ()-> findAll (); foreach ($ cacheas $ key = >$ n) {$ keys [$ n-> attributes ['name'] = $ n-> attributes ['value'];} yii: app ()-> memcache-> set ('keyword', $ keys);} returnYii: app () -> memcache-> get ('keyword ');} |
Through the above array assembly, we can get how to assemble the array to update the database.
Okay, data processing is complete. now we only need to call the relevant data in views/main. php. The keyword is used as an example.
?
Done!
Original article. For more information, see the source!