当前位置: 首页 > 图文教程 > 网络编程 > PHP > 利用PHP实现一种轻量级的MVC结构(原创)

PHP
PHP XML操作类DOMDocument
php jquery 实现新闻标签分类与无刷新分页
php 来访国内外IP判断代码并实现页面跳转
php 计算两个时间戳相隔的时间的函数(小时)
php 日期时间处理函数小结
PHP strtotime函数详解
PHP 抓取新浪读书频道的小说并生成txt电子书的代码
php 空格,换行,跳格使用说明
c#中的实现php中的preg_replace
PHP 分页原理分析,大家可以看看
php 8小时时间差的解决方法小结
PHP 源代码压缩小工具
php 常用类整理
在PHP中检查PHP文件是否有语法错误的方法
PHP simple_html_dom.php+正则 采集文章代码
PHP array_push 数组函数
php 文章采集正则代码
php 需要掌握的东西 不做浮躁的人
phpMyAdmin链接MySql错误 个人解决方案
PHP 获取目录下的图片并随机显示的代码

利用PHP实现一种轻量级的MVC结构(原创)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 62 ::
收藏到网摘: n/a

本文转自:http://hsboy.com/blog/archives/158-uPHPOEOEOECaAEMVCa.html

  PHP的优点就在于轻量和跨平台。它和Apache以及Mysql的联合可以提供一种十分廉价的解决方案,这在开发和部署上都能体现出来。本人之所以执着于PHP也是因为这一点(虽然本人对于PHP的怨言也有不少,暂且不表)。

    MVC结构是不是好的结构,它有哪些优点,是否适合于WEB或者是否适合于使用PHP进行开发的WEB项目,这在很多文章中都提到过。这里÷粤恕J导噬希???HP以及一些现成的开远项目,确实可以做出很清晰简洁的架构,这也是本文的目标所在。

一、Model部分

    Model中包含bean以及bean的有效性检验代码,下面是Bean类的实现:

<?php
class
Bean
{
    protected
$_bean_name = NULL
;
    private
$_bean_array = NULL
;

    
/**
     * set the name of the bean
     *
     * @param $name string the bean name to set
     * @return void
     */
    
public function set_name($name
)
    {
        
$this->_bean_name = $name
;
    }

    
/**
     * get the name of the bean
     *
     * @return string the name of the current bean
     */
    
public function get_name
()
    {
        return
$this->_bean_name
;
    }

    
/** constructor, build a bean from a array and the name of the bean */
    
public function __construct($bean_name, &$bean_array
)
    {
        
$this->set_name($bean_name