MVC调用函数function.php

<?php
    //控制器的调用函数C
    function C($name, $method){
        require_once('/libs/controller/'.$name.'Controller.class.php');
        //eval('$obj = new '.$name.'Controller();$obj->'.$method.'();');
        $controller = $name.'Controller';
        $obj = new $controller();
        $obj -> $method.();
    }

    //模型的调用函数M
    function M($name){
        require_once('/libs/Model/'.$name.'Model.class.php');
        //eval('$obj = new '.$name.'Model();');
        $model = $name.'Model';
        $obj = new $model();
        return $obj;
    }
    
    //视图的调用函数V
    function V($name){
        require_once('/libs/View/'.$name.'View.class.php');
        //eval('$obj = new '.$name.'View();');
        $view = $name.'View';
        $obj = new $view();
        return $obj;
    }
    
    function ORG($path, $name, $params=array()){// path 是路径  name是第三方类名 params 是该类初始化的时候需要指定、赋值的属性,格式为 array(属性名=>属性值, 属性名2=>属性值2……)
        require_once('libs/ORG/'.$path.$name.'.class.php');
        //eval('$obj = new '.$name.'();');
        $obj = new $name();
        if(!empty($params)){
        foreach($params as $key=>$value){
                //eval('$obj->'.$key.' = \''.$value.'\';');
                $obj->$key = $value;
            }
        }
        return $obj;
    }

    //用来过滤非法参数的数据
    //get_magic_quotes_gpc函数判断是否调用魔术方法
    //addslashes函数转义字符串
    function daddslashes($str){
        return (!get_magic_quotes_gpc())?addslashes($str):$str;
    }

?>

 

posted @ 2015-06-07 14:56  banshaohuan  阅读(397)  评论(0编辑  收藏  举报