文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>QeePHP 版 MVCBlog

QeePHP 版 MVCBlog

时间:2008-04-12  来源:qeeify


大家好!小弟是 rainland,今天把 FleaPHP 中自带的 MVC_Blog 用 QeePHP 改写了下,希望大家一起进步,呵呵,错误之处,请留言,我好修改。程序完全是用 FleaPHP 中的数据表,模板也是。所以就很像了,大家肯定感觉亲切。还要感谢老大,给我们这么好的东东。呵呵。
创建应用程序
D:\cd wamp\www
D:\wamp\www\qeephp\scripts\chili.bat qeemvc_blog
实现列表功能
1、首先我们创建一个 posts 控制器:
D:\wamp\www\qeemvc_blog\php script\generate.php controller posts
成功的话是这样的:
Create file 'D:\wamp\www\qeemvc_blog/app/controller/posts_controller.php'
successed.
Create directory 'D:\wamp\www\qeemvc_blog\app\view\posts' successed.

打开 D:\wamp\www\qeemvc_blog/app/controller/posts_controller.php,修改内容为

function __construct(){
parent::__construct(MyApp::instanc());
}
/**
* 默认动作
*/
function actionIndex()
{
$this->view['posts']=Posts::find()->order('created DESC')->all()->query();
}

2、更改数据库配置:config\database.yaml.php
3、创建 Model:
D:\wamp\www\qeemvc_blog\php script\generate.php model post mvcblog_posts
这里的 mvcblog_posts 就是数据库中的数据表名称。
Create file 'D:\wamp\www\qeemvc_blog\app\model\post.php' successed.
4、在 D:\wamp\www\qeemvc_blog\app\view\post 目录下创建一个名为 index.php 的文
件,内容就是 FleaPHP MVCBlog 的模板改过来的。详细的看附件源文件。
5、修改 d:\wamp\www\qeemvc_blog\app\view\_layout\default_layout.php 的内容为


title>QeePHP版MVCBlog/title>

以前 FleaPHP MVCBlog 示例中的 PostIndex.php 模板被拆分了,以便利用 QeePHP 布
局功能简化其他模板的创建。关于 QeePHP 布局功能的详细信息请参考:http://qeeify.com/index.php/2008/03/18/use-layouts-
template.html
预览应用程序
OK,现在通过浏览器访问:http://localhost/qeemvc_blog/public/?controller=posts
接下来,实现查看、新增和删除功能。
实现其他功能
修改 D:\wamp\www\qeemvc_blog/app/controller/posts_controller.php,把其他功能
需要的控制器代码添加进去:
class Controller_Post extends QController_Abstract
{
function __construct(){
parent::__construct(MyApp::instanc());
}
/**
* 默认动作
*/
function actionIndex()
{
$this->view['posts']=Posts::find()->order('created DESC')->all()->query();
}
/**
* 显示及新增页面
*/
function actionAdd(){
$form=$this->form->prepare('posts',$this->request);
if ($this->request->isPOST()) {
try {
$post=new Posts($form);
$post->save();
return $this->redirect($this->url->make('Post','Index'));
}catch (QDB_ActiveRecord_Validate_Exception $ex){
$error=$ex->validate_error;
}
}else {
$error=array();
}
$this->view['error']=$error;
$this->view['form']=$form;
}
/**
* 查看某ID的帖子
*/
function actionView(){
$this->view=array(
'post'=>Posts::find('%PK%= ?',$this->request->id)->query(),
);
}
/**
* * 删除某id的帖子
*/
function actionDelete(){
Posts::destroyWhere('%PK%= ?',$this->request->id);
return $this->redirect($this->url->make('Post','Index'));
}
}

在 D:\wamp\www\qeemvc_blog\app\view\posts 目录下分别创建 view.php 和 add.php
文件看附件中的app\view\post\。
最后,我们还得改一下
D:\wamp\www\qeemvc_blog/app/controller/default_controller.php:
function __construct(){
parent::__construct(MyApp::instanc());
}
function actionIndex(){
return $this->redirect($this->url->make('Post','index'));
}

我们的 MVCBlog 就完成了 :) 源码:
http://qeeify.com/files/2008/03/qeemvc_blog-080331.zip

原文地址:
http://qeeify.com/index.php/2008/03/30/example-qeephp-mvcblog.html
更多信息,请访问 FleaPHP/QeePHP 开源开发框架官方网站:
http://www.fleaphp.org/



相关阅读 更多 +
排行榜 更多 +
粉末星战 v1.0.0 安卓版

粉末星战 v1.0.0 安卓版

休闲益智 下载
粉末星战 v1.0.0 安卓版

粉末星战 v1.0.0 安卓版

休闲益智 下载
火线反恐部队 v1.2 安卓版

火线反恐部队 v1.2 安卓版

飞行射击 下载