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

PHP
PHP实例教程:Output Control输出函数
memcached和mysql主从环境下PHP开发
基于LAMP架构设计的WEB框架
PHP代码:验证IPV6地址是否合法的正则
PHP环境快读搭建绿色软件包PHPnow
PHP教程:$_SERVER的详细参数整理
php获取url字符串截取路径的文件名和扩展名的函数
在命令行下运行PHP脚本[带参数]的方法
PHP 实用代码收集
PHP 时间转换Unix时间戳代码
关于php fread()使用技巧
PHPMailer 中文使用说明小结
php addslashes和mysql_real_escape_string
php cout<<的一点看法
PHP 变量的定义方法
php学习之 认清变量的作用范围
php 静态变量与自定义常量的使用方法
认识并使用PHP超级全局变量
通过具体程序来理解PHP里面的抽象类
php读取xml实例代码

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 58 ::
收藏到网摘: 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