+ -
当前位置:首页 → 问答吧 → 做了个个人网站大家看看

做了个个人网站大家看看

时间:2009-07-14

来源:互联网

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

作者: haha_zhi   发布时间: 2009-07-14

风格不能太豆瓣

作者: 阿辛   发布时间: 2009-07-14

本帖最后由 zhicheng 于 2009-7-14 20:43 编辑

我用Zend做简单CMS也是action里面几乎什么都不写,我估计我们的思路应该差不多,呵呵。

另外想请问,url后面的部分弄成你这种风格,有什么特殊的好处么?

作者: zhicheng   发布时间: 2009-07-14

呵呵,美工差,就逮住豆瓣抄了呗,抄死他我!
好的艺术家抄袭,伟大的艺术家偷窃!
                          ---达芬奇
url后面的部分弄成你这种风格,有什么特殊的好处么?  
没啥意思,看见校内用do  就学了呗, “.”后面的东西可以不写,可以随便写任何东西.例如 .love
就是好玩,好玩+艺术 = 程序 哈哈!

作者: haha_zhi   发布时间: 2009-07-14

http://www.diyinfu.com/look/AGQGMVM1V21SZw%3D%3D.do
我这个没有首页,
我把文章作为首页
其实这个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