做了个个人网站大家看看
时间:2009-07-14
来源:互联网
www.diyinfu.com
给点意见!
用的自己写的框架,仿造了zendframwork点东西,router 可以随便变换 。用了工作单元和实体,dao,对数据库的映射,路由功能,不想按照zend的那种约定,而是自己配map,觉得这样灵活!在action 层面上不用写任何sql语句!我完了整理一下代码,发出来!
作者: haha_zhi 发布时间: 2009-07-14

作者: 阿辛 发布时间: 2009-07-14
我用Zend做简单CMS也是action里面几乎什么都不写,我估计我们的思路应该差不多,呵呵。
另外想请问,url后面的部分弄成你这种风格,有什么特殊的好处么?
作者: zhicheng 发布时间: 2009-07-14
好的艺术家抄袭,伟大的艺术家偷窃!
---达芬奇
url后面的部分弄成你这种风格,有什么特殊的好处么?
没啥意思,看见校内用do 就学了呗, “.”后面的东西可以不写,可以随便写任何东西.例如 .love
就是好玩,好玩+艺术 = 程序 哈哈!
作者: haha_zhi 发布时间: 2009-07-14
我这个没有首页,
我把文章作为首页
其实这个url 可以改成
http://www.diyinfu.com/article/look/AGQGMVM1V21SZw%3D%3D.do
照样能访问。
我的框架能模块化!
其中 我把 $module->defaultModule = article;
所以就缺省了article 了!
这样,我可以缺省任何模块,为首页模块!
作者: haha_zhi 发布时间: 2009-07-14
实体::insertEntity()
.........
其中没有任何提交,插入,查询的语句例如 xxx->docommit();
这其实都是框架中的工作单元干了,其中有个插件。会负责的!
而且得到一个实体,如果在查找相同实体,工作单元不会再次查询数据库的,会从工作单元把你上次的
再给你,如果加入memcache。。缓存,效率是特别高的(现在每加缓存所以作用域只能是一个action)(如果加了,工作单元的缓存作用域就是全局的)!
套框架确实很方便,这个blog一个星期完成的!(别乱测试。。许多没验证呵呵

整理整理我把代码发上来!
这是我的路由类[code]<?php
abstract class Router
{
// private $controller;
protected $action;
protected $method;
protected $tpl;
protected $param;
protected $plugin;
protected $request;
public function __construct($request = null)
{
$this->request = $request;
}
public function getAction()
{
return $this->action;
}
public function getMethod()
{
return $this->method;
}
public function getTpl()
{
return $this->tpl;
}
public function getParam()
{
return $this->param;
}
public function getPlugin()
{
return $this->plugin;
}
}
class ArrayRouter extends Router
{
private $urlMap;
public function getOp($uri)
{
$config = BeanFinder::get("Config");
if($uri =='/' || preg_match("/^\/(?:\?|#)/i",$uri))
{
$uri = '/'.$config->defaultmodule.'/';
$map = $config->loadMapFile($config->defaultmodule."_map.php");
}
else
{
preg_match("/^(?:\/\w++\.php)?\/([^\/\.]*)(.*)?/i",$uri,$module);
$configModule = $config->getModule();
if(empty($module[1]) || empty($configModule) ||!in_array($module[1],$configModule))
{
$map = $config->loadMapFile($config->defaultmodule."_map.php");
}
else
{
if(empty($module[2])||preg_match('/(?:^\.|^\/$)/',$module[2]))
{
$uri = '/'.$module[1].'/';
}
else
{
$uri = $module[2];
}
$map = $config->loadMapFile("$module[1]"."_map.php");
}
}
if($this->match($uri,$map))
{
}
else
{
$uri ="/$config->errorpath/";
$this->match($uri, $map);
}
// $map = $config->loadMapFile("map.php");
// $modulename ='';
// }
}
private function match($uri,$map)
{
foreach ($map as $key => $value)
{
$dealkey = str_replace('/', '\/', $key);
if(preg_match("/^(?:\/\w++\.php)?(?:$dealkey)($|\.|\/.*)/i",$uri,$match))
{
$this->action = $map[$key]['action'];
$this->method = $map[$key]['method'];
if(!empty($map[$key]['tpl']))
$this->tpl = $map[$key]['tpl'];
if(!empty($map[$key]['plugin']))
$this->plugin = $map[$key]['plugin'];
if(!empty($map[$key]['param']))
{
$preg ='';
$param ='';
$param = explode(':',$map[$key]['param']);
foreach($param as $key_p => $value_p)
{
if(!empty($value_p))
{
$preg .="(?:\/)?(?P<$value_p>[^\/\.\?]*)";
}
}
preg_match("/^$preg/",$match[1],$match_p);
foreach($param as $key_p => $value_p)
{
if(!empty($value_p))
{
$this->param[$value_p] = $match_p[$value_p];
}
}
}
return true;
}
}
}
public function getUrl($module="",$action, $method ,$params = null,$other = null)
{
$config = BeanFinder::get("Config");
if(empty($module) ||$module==$config->defaultmodule)
{
$map = $config->loadMapFile($config->defaultmodule."_map.php");
$module="";
}
else
{
$map = $config->loadMapFile("$module"."_map.php");
$module = '/'.$module;
}
foreach($map as $url => $value)
{
if($value['action'] == $action && $value['method'] == $method)
{
if(empty($module) || $module == $url)
$url = "";
if(empty($config->enterfile))
{
$urlquery = $module.$url.'/';
}
else
{
$urlquery = '/'.$config->enterfile.$module.$url.'/';
}
if(empty($value['param']))
$param = "";
else
$param = $value['param'];
if($result = $this->compactParam($param,$params))
{
$urlquery .= $result.'/';
}
if($other != null ||is_array($other))
{
$query = http_build_query($other);
$urlquery .= '?'.$query;
}
$urlquery = substr($urlquery,0,-1).".do";
return $urlquery;
}
}
}
private function compactParam($paramMap ,$params = null)
{
if($params ==null || !is_array($params) || empty($paramMap))
{
return 0;
}
else
{
extract($params);
$param = explode(':',$paramMap);
$result = compact($param);
if(empty($result))
{
return 0;
}
else
{
$strparam = implode('/',$result);
return $strparam;
}
}
}
}[/code]这是其中一个action 的method[code]public function doShow()
{
////////////////////////得到根目录实体////////////////////////
$this->response->rootdirectorysEntity = Directorys::getDirectoryByfId(0);
///////////////////////////////////////////////////////////
$dname = $this->request->getParam("dname");
$directoryEntity = Directorys::getByUrldecodeName($dname);
if($directoryEntity != null)
{
$urlParam = $this->request->saveUrlParam('article','ArticleAction','doShow',array('dname'=>$dname));
$articlesEntity = Articles::getPageSelfAndChildArticleByQueueid($directoryEntity->getQueueId(),8,$this->request,$urlParam);
$childDirectorysEntity = Directorys::getDirectoryByfId($directoryEntity->getId());
if($this->request->getParam('page') <= 1)
$articleFirstEntity = Articles::getFirstByDirectoryIdAndSign($directoryEntity->getId(),'first');
$articlesOrderEntity = Articles::getAllArticleByQueueidOrder($directoryEntity->getQueueId(),'ctime',10);
$this->response->articleFirstEntity = $articleFirstEntity;
$this->response->articlesEntity = $articlesEntity;
$this->response->directoryEntity = $directoryEntity;
$this->response->childDirectorysEntity = $childDirectorysEntity;
$this->response->articlesOrderEntity = $articlesOrderEntity;
$this->response->navigation = substr($this->getNavigation($directoryEntity),0,-1);
$this->response->pageHtml = Articles::$html;
}
else
{
echo "没有该目录!";
exit;
}
}[/code]这是增加文章[code]}
public function doAddarticlesubmit()
{
$title = $this->request->getPost("title");
$content = $this->request->getPostUnhtml("content");
$source = $this->request->getPost("source");
$did = $this->request->getPost("did");
$imagebig = $this->request->getPost("image_big");
$imagesmall = $this->request->getPost("image_small");
$sign = $this->request->getPost("sign");
$sign1 = $this->request->getPost("sign1");
$picarray = $this->request->getPost("pic");
if(!empty($picarray))
{
$pic = serialize($picarray);
}
if(!empty($did))
{
$directoryEntity = Directorys::getById($did);
if($directoryEntity == null)
{
//转入出错例程
exit;
}
else
{
$directoryid = $directoryEntity->getId();
$row['directoryid'] = $directoryid;
$row['queueid'] = $directoryEntity->getQueueId();
$row['title'] = $title;
$row['content'] = addslashes($content);
$row["source"] = $source;
$row["imagebig"] = $imagebig;
$row["imagesmall"] = $imagesmall;
$row["sign"] = $sign;
$row["sign1"] = $sign1;
$row["pic"] = $pic;
Articles::insertEntity($row);
$this->response->setRedirect($this->request->getUrl("admin","AdminAction","doDirectory"));
}
}
else
{
//转入出错例程
exit;
}
}[/code]
作者: haha_zhi 发布时间: 2009-07-14
作者: niceup 发布时间: 2009-07-15

作者: suncuan 发布时间: 2009-07-16
作者: ahsxw 发布时间: 2009-07-17
作者: fvzone 发布时间: 2009-07-18
作者: lukui306 发布时间: 2009-07-20
作者: anyifei 发布时间: 2009-07-21
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28