设为首页收藏本站

简体中文 繁體中文 English 日本語 Deutsch 한국 사람 بالعربية TÜRKÇE português คนไทย french

搜索
热搜: 活动 交友 discuz

进来看看这段php代码,@smyz [复制链接]
查看:53 | 回复:9

195

主题

828

回帖

2303

积分

金牌会员

积分
2303
发表于 2013-8-25 18:23:28 | 显示全部楼层 |阅读模式
本帖最后由 aite.me 于 2013-8-25 18:24 编辑
[ol]
  • ControllerName = (isset($_GET[$Config['UrlControllerName']]) && !empty($_GET[$Config['UrlControllerName']])) ? trim($_GET[$Config['UrlControllerName']]) : 'index';
  •         $this -> ActionName = (isset($_GET[$Config['UrlActionName']]) && !empty($_GET[$Config['UrlActionName']])) ? trim($_GET[$Config['UrlActionName']]) : 'IndexAction';
  •         $this -> ControllerFile = _CONTROLLER. $this -> ControllerName . '.php';
  •     }
  •     public function ControllerStart() {
  •         (is_file($this -> ControllerFile) && require $this -> ControllerFile) || (is_file(_CONTROLLER . 'index.php') && require _CONTROLLER . 'index.php') || self::notice('Controller File No Found !');
  •         class_exists($this -> ControllerName) || ($this -> ControllerName = 'index' && class_exists($this -> ControllerName)) || self::notice('Controller Class No Found !');
  •         $methods = get_class_methods($this -> ControllerName);
  •         in_array($this -> ActionName, $methods, true) || ($this -> ActionName = 'IndexAction' && in_array($this -> ActionName, $methods, true)) || self::notice('Controller Method No Found !');
  •         $KernelController = new $this -> ControllerName($_GET);
  •         $KernelController -> {$this -> ActionName}();
  •     }
  •     static public function notice($notice) {
  •         exit($notice);
  •     }
  •     static public function filter(&$array, $function) {
  •         if(!is_array($array)) return $array = $function($array);
  •         foreach($array as $key => $value) (is_array($value) && $array[$key] = Kernel::filter($value, $function)) || $array[$key] = $function($value);
  •         return $array;
  •     }
  • }
  • class KernelView {
  •     public $ViewValue;
  •     public function __construct() {
  •     }
  •     public function _view($file = null) {
  •         $file = _VIEW . $file . '.php';
  •         extract($this -> ViewValue);
  •         if(is_file($file)) return require $file;
  •         Kernel::notice('View File No Found !');
  •     }
  • }
  • class KernelModel {
  • }
  • class KernelController {
  •     public $KernelView;
  •     public $KernelClass;
  •     public $KernelModel;
  •     public function __construct() {
  •         global $Config;
  •         $this -> KernelView = new KernelView();
  •     }
  •     public function __set($name, $value = null) {
  •         $this -> KernelView -> ViewValue[$name] = $value;
  •     }
  •     public function _view($file = null) {
  •         global $Config;
  •         $KernelSelfPropertyKey = array_keys(get_class_vars('KernelController'));
  •         $ControllerPropertyParam = get_object_vars($this);
  •         foreach($ControllerPropertyParam as $key=>$val)
  •         {
  •             if(!in_array($key, $KernelSelfPropertyKey))        $this -> KernelView -> ViewValue[$key] = $val;
  •         }
  •         $this -> KernelView -> _view($file);
  •     }
  •     public function _model($file, $ClassName = null) {
  •         $ClassName = $ClassName == null ? $file : $ClassName;
  •         $file = _MODEL . $file . '.php';
  •         if(is_file($file)) {
  •             require $file;
  •             if(!class_exists($ClassName)) Kernel::notice('Class No Found !');
  •             if(!isset($this -> KernelModel[$ClassName])) $this -> KernelModel[$ClassName] = new $ClassName();
  •             return $this -> KernelModel[$ClassName];
  •         }
  •     }
  •     public function _class($file, $ClassName = null) {
  •         $ClassName = $ClassName == null ? $file : $ClassName;
  •         $file = _CLASS . $file . '.php';
  •         if(is_file($file)) {
  •             require $file;
  •             if(!class_exists($ClassName)) Kernel::notice('Class No Found !');
  •             if(!isset($this -> KernelClass[$ClassName])) $this -> KernelClass[$ClassName] = new $ClassName();
  •             return $this -> KernelClass[$ClassName];
  •         }
  •     }
  • }
  • ?>[/ol]复制代码学着用mvc模式做程序了,看了下amp,我自己试着折腾,require进来的文件中模型和视图的类名不能一样,否则控制器出_view方**出错,另外想说一下,数据库连接放在子模型中还是主模型中?示范代码没有做文件系统\0之类的安全处理。
  • 167

    主题

    1495

    回帖

    3507

    积分

    论坛元老

    积分
    3507
    发表于 2013-8-25 18:25:35 | 显示全部楼层
    好高深


    .f

    116

    主题

    808

    回帖

    1990

    积分

    金牌会员

    积分
    1990
    发表于 2013-8-25 18:30:40 | 显示全部楼层
    这是什么框架

    195

    主题

    828

    回帖

    2303

    积分

    金牌会员

    积分
    2303
     楼主| 发表于 2013-8-25 18:32:38 | 显示全部楼层
    "

    边看amysql.php边研究mvc然后顺手写。

    116

    主题

    808

    回帖

    1990

    积分

    金牌会员

    积分
    1990
    发表于 2013-8-25 18:30:00 | 显示全部楼层
    写框架的都是牛人

    195

    主题

    828

    回帖

    2303

    积分

    金牌会员

    积分
    2303
     楼主| 发表于 2013-8-25 18:55:40 | 显示全部楼层
    "

    不试着学习怎么能提升自己的技术呢?不可能看看就会了啊,实际操作有利于提升自己。

    7

    主题

    1926

    回帖

    3891

    积分

    论坛元老

    积分
    3891
    发表于 2013-8-25 19:06:15 | 显示全部楼层
    既然是MVC,类名肯定是有规则的,模型和视图的类怎么会写成一样?

    195

    主题

    828

    回帖

    2303

    积分

    金牌会员

    积分
    2303
     楼主| 发表于 2013-8-25 18:55:00 | 显示全部楼层
    "

    我明白了,高手。

    224

    主题

    2144

    回帖

    5032

    积分

    论坛元老

    积分
    5032
    发表于 2013-8-25 19:13:02 | 显示全部楼层
    1、类不可同名。
    2、print_r($Amysql); 可以看到所有结构
    3、 \0? AMP只是一基本MVC框架,其它什么的再按需扩展拉

    195

    主题

    828

    回帖

    2303

    积分

    金牌会员

    积分
    2303
     楼主| 发表于 2013-8-25 19:14:39 | 显示全部楼层

    smyz 发表于 2013-8-25 22:55

    1、类不可同名。
    2、print_r($Amysql); 可以看到所有结构
    3、 \0? AMP只是一基本MVC框架,其它什么的再按需 ...

    明白了,\0就是php的文件系统攻击,null(\0)会截断字符串。
    您需要登录后才可以回帖 登录 | 立即注册

    论坛客服/商务合作/投诉举报:2171544 (QQ)
    落伍者创建于2001/03/14,本站内容均为会员发表,并不代表落伍立场!
    拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论!
    落伍官方微信:2030286 邮箱:(djfsys@gmail.com|tech@im286.com)
    © 2001-2014

    浙公网安备 33060302000191号

    浙ICP备11034705号 BBS专项电子公告通信管[2010]226号

      落伍法律顾问: ITlaw-庄毅雄

    Archiver|手机版|Discuz! X

    GMT+8, 2026-3-25 12:28 , Processed in 0.017778 second(s), 3 queries , Gzip On, Redis On.

    返回顶部