【phpcms-v9】content_form.calss.php文件分析-内容添加页面动态表单的生成原理
2016-03-27 09:40
856 查看
[html] view
plain copy
print?
<?php
//此文件主要根据caches/caches_model/caches_data/model_field_1.php文件中的模型字段来动态的生成表单
//路径:phpcms/caches/caches_model/caches_data/content_form.class.php文件,主要用来返回内容添加页面左侧动态生成的表单
//此类主要用来动态生成内容添加页面的所有表单:内容添加页面左侧表单不是直接写在html中的,而是通过程序动态生成的,现将其分析一下
//此文件需要参考:model_feild_模型ID.cache.php文件,因为通过后台 模型管理->字段管理 中所有已存在或新加的字段都会被缓存在这个文件中,如【下图2所示】
class content_form {
var $modelid;//模型id 1-文章模型 2-图片模型 3-下载模型 ,不同的模型在添加内容时会动态生成不同的表单
var $fields;//所有模型字段信息
var $id;
var $formValidator;//表单验证
function __construct($modelid,$catid = 0,$categorys = array()) {
$this->modelid = $modelid;
$this->catid = $catid;
$this->categorys = $categorys;
$this->fields = getcache('model_field_'.$modelid,'model');//此缓存文件主要用来缓存模型字段信息
$this->siteid = get_siteid();
}
//此方法主要用来获取所有动态生成好的表单,以便于在前台循环显示
function get($data = array()) {
$_groupid = param::get_cookie('_groupid');
$this->data = $data;
if(isset($data['id'])) $this->id = $data['id'];
$info = array();
$this->content_url = $data['url'];
/**
* $this->fields:主要存放从model_field_模型id.cache.php文件中获取过来的所有模型字段信息
* $field:单个模型字段信息
*/
foreach($this->fields as $field=>$v) {
if(defined('IN_ADMIN')) {
if($v['iscore'] || check_in($_SESSION['roleid'], $v['unsetroleids'])) continue;
} else {
if($v['iscore'] || !$v['isadd'] || check_in($_groupid, $v['unsetgroupids'])) continue;
}
/**
* 表单类型:formtype
* 对应 后台->模型管理->字段管理->类型
* 对应 content_form.class.php文件中方法的名称
* 对应 caches/caches_model/caches_data/model_field_模型id.cache.php文件中键名
* 注意:通过 后台->模型管理->字段管理->添加字段 ,添加的新字段都将被缓存到model_field_模型id.cache.php文件中
*/
$func = $v['formtype'];//表单类型
$value = isset($data[$field]) ? htmlspecialchars($data[$field], ENT_QUOTES) : '';//表单值
if($func=='pages' && isset($data['maxcharperpage'])) {
$value = $data['paginationtype'].'|'.$data['maxcharperpage'];
}
if(!method_exists($this, $func)) continue;
/**
* 1.$func:假设模型字段名称为text,则会调用$this->text()方法
* 2.$this->text()方法会生成并返回一个text类型的表单,如:<input type="text" name="info['keywords']" value="">
* 3.后面程序会将生成的表单放到$info[][]二维数组中,前台只需要循环此数组即可将网页所有的表单都呈现出来
*/
$form = $this->$func($field, $value, $v);
if($form !== false) {
//默认情况下此常量已经被定义了
if(defined('IN_ADMIN')) {
//基本信息字段:基本信息字段将在添加页面左侧显示
if($v['isbase']) {
//添加内容页面:左侧部分的表单名称
$star = $v['minlength'] || $v['pattern'] ? 1 : 0;
$info['base'][$field] = array('name'=>$v['name'], 'tips'=>$v['tips'], 'form'=>$form, 'star'=>$star,'isomnipotent'=>$v['isomnipotent'],'formtype'=>$v['formtype']);
} else {
//添加内容页面:右侧部分的表单名称
//$field:thumb、relation、inputtime、islink、template、allow_comment、readpoint
$star = $v['minlength'] || $v['pattern'] ? 1 : 0;
$info['senior'][$field] = array('name'=>$v['name'], 'tips'=>$v['tips'], 'form'=>$form, 'star'=>$star,'isomnipotent'=>$v['isomnipotent'],'formtype'=>$v['formtype']);
}
} else {
$star = $v['minlength'] || $v['pattern'] ? 1 : 0;
$info[$field] = array('name'=>$v['name'], 'tips'=>$v['tips'], 'form'=>$form, 'star'=>$star,'isomnipotent'=>$v['isomnipotent'],'formtype'=>$v['formtype']);
}
}
}
return $info;
}
//text方法主要用来生成一个text类型的表单:<input type="text" name="info[]" value="" />
function text($field, $value, $fieldinfo) {
}
//textarea方法主要用来生成一个textarea类型的表单:<textarea name="info[]" ></textarea>
function textarea($field, $value, $fieldinfo) {
}
//editor方法主要用来生成一个在线编辑器,如:ckeditor编辑器
function editor($field, $value, $fieldinfo) {
}
function catid($field, $value, $fieldinfo) {
}
function title($field, $value, $fieldinfo) {
}
//box方法主要用来生成radio、select、checkbox类型的表单:<input type="radio" name="info[]" value="" />
function box($field, $value, $fieldinfo) {
}
//image方法主要用来生成上传文件的输入框和上传文件按钮
function image($field, $value, $fieldinfo) {
}
function images($field, $value, $fieldinfo) {
}
function number($field, $value, $fieldinfo) {
}
}
?>
plain copy
print?
<?php
//此文件主要根据caches/caches_model/caches_data/model_field_1.php文件中的模型字段来动态的生成表单
//路径:phpcms/caches/caches_model/caches_data/content_form.class.php文件,主要用来返回内容添加页面左侧动态生成的表单
//此类主要用来动态生成内容添加页面的所有表单:内容添加页面左侧表单不是直接写在html中的,而是通过程序动态生成的,现将其分析一下
//此文件需要参考:model_feild_模型ID.cache.php文件,因为通过后台 模型管理->字段管理 中所有已存在或新加的字段都会被缓存在这个文件中,如【下图2所示】
class content_form {
var $modelid;//模型id 1-文章模型 2-图片模型 3-下载模型 ,不同的模型在添加内容时会动态生成不同的表单
var $fields;//所有模型字段信息
var $id;
var $formValidator;//表单验证
function __construct($modelid,$catid = 0,$categorys = array()) {
$this->modelid = $modelid;
$this->catid = $catid;
$this->categorys = $categorys;
$this->fields = getcache('model_field_'.$modelid,'model');//此缓存文件主要用来缓存模型字段信息
$this->siteid = get_siteid();
}
//此方法主要用来获取所有动态生成好的表单,以便于在前台循环显示
function get($data = array()) {
$_groupid = param::get_cookie('_groupid');
$this->data = $data;
if(isset($data['id'])) $this->id = $data['id'];
$info = array();
$this->content_url = $data['url'];
/**
* $this->fields:主要存放从model_field_模型id.cache.php文件中获取过来的所有模型字段信息
* $field:单个模型字段信息
*/
foreach($this->fields as $field=>$v) {
if(defined('IN_ADMIN')) {
if($v['iscore'] || check_in($_SESSION['roleid'], $v['unsetroleids'])) continue;
} else {
if($v['iscore'] || !$v['isadd'] || check_in($_groupid, $v['unsetgroupids'])) continue;
}
/**
* 表单类型:formtype
* 对应 后台->模型管理->字段管理->类型
* 对应 content_form.class.php文件中方法的名称
* 对应 caches/caches_model/caches_data/model_field_模型id.cache.php文件中键名
* 注意:通过 后台->模型管理->字段管理->添加字段 ,添加的新字段都将被缓存到model_field_模型id.cache.php文件中
*/
$func = $v['formtype'];//表单类型
$value = isset($data[$field]) ? htmlspecialchars($data[$field], ENT_QUOTES) : '';//表单值
if($func=='pages' && isset($data['maxcharperpage'])) {
$value = $data['paginationtype'].'|'.$data['maxcharperpage'];
}
if(!method_exists($this, $func)) continue;
/**
* 1.$func:假设模型字段名称为text,则会调用$this->text()方法
* 2.$this->text()方法会生成并返回一个text类型的表单,如:<input type="text" name="info['keywords']" value="">
* 3.后面程序会将生成的表单放到$info[][]二维数组中,前台只需要循环此数组即可将网页所有的表单都呈现出来
*/
$form = $this->$func($field, $value, $v);
if($form !== false) {
//默认情况下此常量已经被定义了
if(defined('IN_ADMIN')) {
//基本信息字段:基本信息字段将在添加页面左侧显示
if($v['isbase']) {
//添加内容页面:左侧部分的表单名称
$star = $v['minlength'] || $v['pattern'] ? 1 : 0;
$info['base'][$field] = array('name'=>$v['name'], 'tips'=>$v['tips'], 'form'=>$form, 'star'=>$star,'isomnipotent'=>$v['isomnipotent'],'formtype'=>$v['formtype']);
} else {
//添加内容页面:右侧部分的表单名称
//$field:thumb、relation、inputtime、islink、template、allow_comment、readpoint
$star = $v['minlength'] || $v['pattern'] ? 1 : 0;
$info['senior'][$field] = array('name'=>$v['name'], 'tips'=>$v['tips'], 'form'=>$form, 'star'=>$star,'isomnipotent'=>$v['isomnipotent'],'formtype'=>$v['formtype']);
}
} else {
$star = $v['minlength'] || $v['pattern'] ? 1 : 0;
$info[$field] = array('name'=>$v['name'], 'tips'=>$v['tips'], 'form'=>$form, 'star'=>$star,'isomnipotent'=>$v['isomnipotent'],'formtype'=>$v['formtype']);
}
}
}
return $info;
}
//text方法主要用来生成一个text类型的表单:<input type="text" name="info[]" value="" />
function text($field, $value, $fieldinfo) {
}
//textarea方法主要用来生成一个textarea类型的表单:<textarea name="info[]" ></textarea>
function textarea($field, $value, $fieldinfo) {
}
//editor方法主要用来生成一个在线编辑器,如:ckeditor编辑器
function editor($field, $value, $fieldinfo) {
}
function catid($field, $value, $fieldinfo) {
}
function title($field, $value, $fieldinfo) {
}
//box方法主要用来生成radio、select、checkbox类型的表单:<input type="radio" name="info[]" value="" />
function box($field, $value, $fieldinfo) {
}
//image方法主要用来生成上传文件的输入框和上传文件按钮
function image($field, $value, $fieldinfo) {
}
function images($field, $value, $fieldinfo) {
}
function number($field, $value, $fieldinfo) {
}
}
?>
相关文章推荐
- 【phpcms-v9】前台模板文件中{pc}标签的执行流程
- PHPCMSV9 乱解读 之 PHPCMS V9的MVC
- 一些PHP性能优化
- Zend Studio的常用快捷键
- php7.0.2安装
- PHP中如何设置error_reporting错误报告级别
- HDU_ACM_A+B for Input-Output Practice (VIII)
- HDU_ACM_A+B for Input-Output Practice (VII)
- HDU_ACM_A+B for Input-Output Practice (VI)
- HDU_ACM_A+B for Input-Output Practice (V)
- HDU_ACM_A+B for Input-Output Practice (IV)
- PHP 防止SQL注入
- php常用图片处理类
- PHP图片处理之图片背景、画布操作
- PHP连接数据库实现注册页面的增删改查操作
- ThinkPHP 表单令牌验证功能
- laravel后台可修改配置自动加载
- php中的类、对象
- PHP7新建扩展
- 【学习笔记】PHP实现页面静态化