自己动手写CMS
<?php/* * 简易的CMS插件,可供借鉴或者扩展 * * ---- 流程: * 定义内容; * 分类与组织内容 * 存储内容 * 操作控制内容 * * 定义内容: * 制定目标; * 确定需要的内容类型 * 目标用户定位 * 确定目标用户需要何种技术 * * 分类与组织内容: * 按内容所属的逻辑层级关系来划分 * 按内容的种类来划分,比如video/text/audio等等 * * 存储内容: * 关系数据库 * XML * 文本文件 * * 操作控制内容: * 对操作进行颗粒度分离 * 提供足够的元数据信息 * 内容的描述 * 外部展示(web/xml/html),以及定义UI */require_once 'db.php';abstract class SimpleCMS {}class SimpleCMS_Model_ContentType {/** * @var FirePhpHelper */protected $_firePhpHelper = null;/** * @var CoreDb */protected $_dbo = NULL;protected $_tableName = 'content_types';protected $_primaryKey = 'ctype_id';protected $_nameField = 'ctype_name';protected $_descriptionField = 'ctype_description';protected $_createdField = 'created_at';protected $_updatedField = 'updated_at';/** * 构造函数 */function __construct(){$this->_firePhpHelper = FirePhpHelper::getInstance();}/** * 查找内容类型列表 * * @var mixed $cond * @var int|array $limit * @var string $fields * * @return array */function getAll($cond=null,$limit=null,$fields='*'){}/** * 更新内容类型记录,参数中必须带着主键字段 * * @var array $row * * @return boolean */function update(array $row){if (isset($row[$this->_primaryKey])){$row[$this->_updatedField] = CURRENT_TIMESTAMP;$sql = CoreDbSqlHelper::getUpdateSQL($this->_dbo,$row,$this->_primaryKey,$this->_tableName);return $this->_dbo->execute($sql,$row,true);}return false ;}/** * 添加一个内容类型,返回插入的主键值 * * @var string $name 类型名 * @var string $description 描述 * @var array $extra 额外字段属性 * * @return int * @throws SqlQueryException */function add($name,$description,array $extra=null){$row = array($this->_nameField => $name ,$this->_descriptionField => $description ,$this->_createdField => CURRENT_TIMESTAMP ,);if ($extra){$row = array_merge($row,$extra);}$sql = CoreDbSqlHelper::getInsertSQL($row,$this->_tableName);if ($this->_dbo->execute($sql,$row,true))return $this->_dbo->lastInsertId();return false;}/** * 类型主键是否存在 * * @var string $primaryKey * @return boolean */function existsByPrimaryKey($primaryKey){return $this->_dbo->getDbUtils()->findCount($this->_tableName,array($this->_primaryKey=>(int) $primaryKey),$this->_primaryKey);}/** * 类型名称是否存在 * * @var string $name * @return boolean */function existsByName($name){return $this->_dbo->getDbUtils()->findCount($this->_tableName,array($this->_nameField=>$name),$this->_primaryKey);}}?
未完,待续...
1 楼 vb2005xu 2011-04-27 smarty 插件使用例子: 截取HTML <%{$records[i].content|strip_tags|stripslashes|truncate:240}%>