| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- // +----------------------------------------------------------------------
- // |
- // +----------------------------------------------------------------------
- // |
- // +----------------------------------------------------------------------
- // |
- // +----------------------------------------------------------------------
- // |
- // +----------------------------------------------------------------------
- // +----------------------------------------------------------------------
- // | 字段模型
- // +----------------------------------------------------------------------
- namespace addons\cms\model;
- use think\Model;
- /**
- * 字段模型
- */
- class ModelField extends Model
- {
- protected $name = 'cms_field';
- protected $autoWriteTimestamp = true;
- public function getSettingAttr($value, $data)
- {
- return is_array($value) ? $value : (array) json_decode($data['setting'], true);
- }
- public function setSettingAttr($value)
- {
- return is_array($value) ? json_encode($value) : $value;
- }
- public function getExtendHtmlAttr($value, $data)
- {
- $result = preg_replace_callback("/\{([a-zA-Z]+)\}/", function ($matches) use ($data) {
- if (isset($data[$matches[1]])) {
- return $data[$matches[1]];
- }
- }, $data['extend']);
- return $result;
- }
- //生成模型字段缓存
- public function model_field_cache()
- {
- $cache = [];
- $modelList = Models::where('module', 'cms')->select();
- foreach ($modelList as $v) {
- $data = ModelField::where(["modelid" => $v['id'], "status" => 1])->order('listorder DESC, id DESC')->select()->toArray();
- $fieldList = [];
- foreach ($data as $rs) {
- if (!empty($rs['setting'])) {
- $rs = array_merge($rs, $rs['setting']);
- }
- $fieldList[$rs['name']] = $rs;
- }
- $cache[$v['id']] = $fieldList;
- }
- cms_cache('ModelField', $cache);
- return $cache;
- }
- }
|