menu 文章
基于Typecho的社区系统2
开心就好

功能与数据都折腾清楚了,就想着开始具体实现了

首先要做的就是需要能够修改系统的路由。这个并没有费很大力气,直接百度搜到了一款路由编辑插件RoutesHelper,做了一点修改,然后就正式开动吧!!!

路由到组件

一开始添加的路由是:

 Helper::addRoute(array('name'=>'login','url'=>'/login','widget'=>'Widget_Login','action'=>'render'))

并新建了文件Widget_Login

class Widget_Login extends Widget_Abstract_Users{
    public function render(){
        //todo
        require_once $this->_themeDir.'user/login.php';//引入模版文件
    }
    public function need($fileName){
        require $this->_themeDir.$fileName;//引入模版文件
    }
}

这样就可以把做好的模版文件加载并显示

然后是注册功能,又得新建一个Widget_Register文件,类似的函数又要写一遍……

但是仔细看Archive.php文件发现完全不需要新建文件,直接把路由指向Widget_Archive即可:

Helper::addRoute(array('name'=>'login','url'=>'/login','widget'=>'Widget_Archive','action'=>'render'))

然后在Widget_Archive组件中的execute函数添加相应的handles,execute会根据handles的设置执行对应的函数:

$handles = array(
    //默认设置
    'login'=>'loginHandle',
    ……    //其他自定义路由
)

根据定义的hangles写出处理函数:

private function loginHandle(Typecho_Db_Query $select, &$hasPushed){
    $hasPushed = true;    //是否已经取得了数据,这里因为不需要再获取数据,所以设置为true
    $this->setArchiveType($this->parameter->type);
    $this->setMetaTitle('登录');
    $this->setThemeFile('user/login.php');
}
……  //其他的函数

这样一来的话,很快就能够看到功能的基础页面

未完待续……

2015-10-15 share

评论已关闭

主题色
强调色
登录
用户名/邮箱不能为空
密码不能为空
用户名不能为空
邮箱不能为空
登录密码不能为空
验证码不能为空

或者使用其他方式登录