phpCMS学习笔记
1、phpcms的目录结构
| – api 接口文件目录
| – caches 缓存文件目录
| – configs 系统配置文件目录
| – caches_* 系统缓存目录
| – phpcms phpcms框架主目录
| – languages 框架语言包目录
| – libs 框架主类库、主函数库目录
| – model 框架数据库模型目录
| – modules 框架模块目录
| – templates 框架系统模板目录
| – phpsso_server phpsso主目录
| – statics 系统附件包
| – css 系统css包
| – images 系统图片包
| – js 系统js包
| – uploadfile 网站附件目录
| – admin.php 后台管理入口
| – index.php 程序主入口
| – crossdomain.xml FLASH跨域传输文件
| – robots.txt 搜索引擎蜘蛛限制配置文件
| – favicon.ico 系统icon图标
2、URL分析:
index.php?m=content&c=index&a=init
content 模块
index 控制器
init 方法
模块访问方法[示例]:
http://yourdomain.com/index.php?m=content&c=index&a=show&id=1
m = content 为模型/模块名称 位于phpcms/modules/content
c = index 为控制器名称 位于phpcms/modules/content/index.php
a = show 为时间名称 位于phpcms/modules/content/index.php 中show()方法
id = 1 为其他参数 与正常get传递参数形式相同
3、phpCMS的MVC模式
MVC开发模式:
M目录 phpcms/model
V目录 phpcms/templates
C目录 phpcms/modules
4、模板的加载方式
1)前台方法加载模板:
include template('content','index',$default_style)
#phpcms/libs/functions/global.func.php
前台使用模板解析技术
#phpcms\templates\$default_style
2)后台方法加载模板:
include $this->admin_tpl('link_list');
#phpcms\modules\模块\templates
后台使用的是页面包含技术
5、修改默认模块、控制器和方法:
caches\configs \route.php
'default'=>array('m'=>'admin', 'c'=>'index', 'a'=>'init'),
6、模型model:
1)自定义model
phpcms\libs\user_model.class.php
pc_base::load_sys_class('model', '', 0);
class user_model extends model {
function __construct() {
$this->db_config = pc_base::load_config('database');
$this->db_setting = 'default';
$this->table_name = 'user';
parent::__construct();
}
}
2)系统model类
phpcms\libs\model.class.php
7、数据库操作
#phpcms/libs/classes/model.class.php
#phpcms/libs/classes/mysql.class.php
1)select();
#select * from user;
$this->user->select();
#select * from user where id=3;
$this->user->select('id=3');
2)get_one();
#select * from user;
$this->user->get_one();
3)count();
#select count(*) from user;
$this->user->count();
4)insert();
#insert into user('username','password') values('user22','22');
$data=array('username'=>'user11','password'=>'123');
$this->user->insert($data);
5)insert_id();
$this->user->insert_id();
6)update();
#update user set username='user11',password='123' where id=3;
$data=array('username'=>'user11','password'=>'123');
$where='id=3';
$this->user->update($data,$where);
7)delete();
#delete from user where id=3;
$this->user->delete('id=3');
8)query();
#select * from user;
//查user表数据
$sql="select * from user";
$rst=$this->user->query($sql);
//把结果集变成数组
while($row=mysql_fetch_assoc($rst)){
$rows[]=$row;
}
8、phpcms的一些常量
SYS_TIME #1444702184
WEB_PATH #/mypc
JS_PATH #http://localhost/mypc/statics/js/
CSS_PATH #http://localhost/mypc/statics/css/
IMG_PATH #http://localhost/mypc/statics/images/
APP_PATH #http://localhost/mypc/
9、phpcms的数据库配置
#phpcms/caches/configs/database.php
10、phpcms的系统配置
#caches/configs/system.php
11、页面跳转
showmessage('删除成功','index.php?m=content&c=index&a=init');
#phpcms/libs/functions/global.func.php
12、安全控制
defined('IN_PHPCMS') or exit('No permission resources.');
13、phpcms
#phpcms\base.php
加载系统模型:
pc_base::load_model('user_model');
#phpcms\model\user_model.class.php
加载系统类:
pc_base::load_sys_class('model', '', 0);
#phpcms\libs\classes\mail.class.php
加载应用类:
pc_base::load_app_class('model', '', 0);
#phpcms\modules\czh\classes\mail.class.php
加载系统函数:
pc_base::load_sys_func('model', 0);
#phpcms\libs\functions\mail.func.php
加载应用函数:
pc_base::load_app_func('model', 0);
#phpcms\modules\czh\functions
\mail.func.php
14、phpCMS的分页技术
1)前台模板的分页设置
{pc:get sql="select * from v9_czh" page="$_GET[page]" num="2"}
{loop $data $value}
{php print_r($value)}
{/loop}
{/pc}
{$pages}
2)后台模板分页的设置
$page = isset($_GET['page']) && intval($_GET['page']) ? intval($_GET['page']) : 1;
$row = $this->db->listinfo($where,$order = '',$page, $pages = '3');
$pages = $this->db->pages;
15、phpcms模板解析技术
1.标签解析
{$name}
2.loop标签
{loop $rows $row}
<tr>
<td>{$row['id']}</td>
<td>{$row['username']}</td>
<td>{$row['password']}</td>
<td><a href="index.php?m=content&c=index&a=delete&id={$row['id']}">删除</a></td>
</tr>
{/loop}
3.if标签
{for $i=0;$i<10;$i++}
{if $i%2==0}
<h1 style='background:#888'>{$i}</h1>
{else}
<h1>{$i}</h1>
{/if}
{/for}
4.for标签
{for $i=0;$i<10;$i++}
<h1>{$i}</h1>
{/for}
5.包含模板
{template 'content','header'}
6.定义变量
{php $i=5;$a=20}
7.使用函数
<h1>{substr(strtoupper($name),0,3)}</h1>
8.系统变量
{php define('HOST','localhost')}
<h1>{HOST}</h1>
9.pc:get标签
{pc:get sql="select * from user" return="rows"}
{loop $rows $row}
<tr>
<td>{$row['id']}</td>
<td>{$row['username']}</td>
<td>{$row['password']}</td>
<td><a href="index.php?m=content&c=index&a=delete&id={$row['id']}">删除</a></td>
</tr>
{/loop}
{/pc}
了解更多,学习地址