+ -
当前位置:首页 → 问答吧 → MyPic v2.0 完全注释~源码~

MyPic v2.0 完全注释~源码~

时间:2009-03-05

来源:互联网

MyPic v2.0 Beta 发布!(2009.03.05)

安装目录 /install.php 安装

后台用户密码: admin/admin

本版本仅供测试,请勿泄露到源码站或者其它地方,谢谢!

功能列表什么的就不列了~

单入口MVC模式~

放在这里的是全注释测试版本,错误难免~

接受批评,建议,指点!

2.0演示: http://www.diqiye.com/mp/

1.32演示: http://www.diqiye.com/mypic

[ 本帖最后由 wbsifan 于 2009-3-5 15:15 编辑 ]

MyPic v2.0 Beta.rar (635.58 KB)

下载次数:244

2009-3-5 15:15

作者: 小鱼哥哥   发布时间: 2009-03-05

[php]class model extends base {
        protected $db;
        protected $_options = array();
        protected $_table = array();
        protected $_data = array();
        protected $validate = array();
        protected $mp;
        public function __construct()
        {
        }
        public function initModel()
        {
                $this -> db = getConn();
                dump($this->db);
                $this -> mp = &$GLOBALS['_MP'];
        }
        public function getvo()
        {
                return $this -> _data;
        }
        public function __set($name, $value)
        {
                $this -> _data[$name] = $value;
        }
        public function __get($name)
        {
                if (isset($this -> _data[$name])) {
                        return $this -> _data[$name];
                } elseif (property_exists($this, $name)) {
                        return $this -> $name;
                } else {
                        return null;
                }
        }
        public function find()
        {
                $sql = $this -> parse_select();
                $arr = $this -> db -> getone($sql);
                return $arr;
        }
        public function findAll()
        {
                $sql = $this -> parse_select();
                $arr = $this -> db -> getall($sql);
                return $arr;
        }
        public function result($num = 0)
        {
                $sql = $this -> parse_select();
                $arr = $this -> db -> result($sql, $num);
                return $arr;
        }
        public function save($data = null)
        {
                $table = $this -> parse_table();
                $where = $this -> parse_where();
                if (!empty($where)) {
                        return $this -> db -> update($table, $data, $where);
                } else {
                        return $this -> db -> insert($table, $data);
                }
        }
        public function del()
        {
                $table = $this -> parse_table();
                $where = $this -> parse_where();
                if (!$where) {
                        throwError(L('error.nowhere'));
                }
                return $this -> db -> delete($table, $where);
        }
        public function parse_select()
        {
                if (!empty($this -> _options['sql'])) {
                        $sql = $this -> _options['sql'];
                        unset($this -> _options['sql']);
                } else {
                        $field = '*';
                        if (!empty($this -> _options['field'])) {
                                if (is_array($this -> _options['field'])) {
                                        $field = implode(',', $this -> db -> deal_field($this -> _options['field']));
                                } else {
                                        $field = $this -> _options['field'];
                                }
                                unset($this -> _options['field']);
                        }
                        $table = $this -> parse_table();
                        $where = $this -> parse_where();
                        !empty($where) && $where = ' WHERE ' . $where;
                        $order = '';
                        if (!empty($this -> _options['order'])) {
                                $order = ' ORDER BY ' . $this -> _options['order'];
                                unset($this -> _options['order']);
                        }
                        $limit = '';
                        if (!empty($this -> _options['limit'])) {
                                $limit = ' LIMIT ' . $this -> _options['limit'];
                                unset($this -> _options['limit']);
                        }
                        $sql = "SELECT {$field} FROM {$table}{$where}{$order}{$limit}";
                }
                return $this -> deal_table($sql);
        }
        protected function parse_where()
        {
                $where = '';
                if (!empty($this -> _options['where'])) {
                        if (is_array($this -> _options['where'])) {
                                $where = $this -> db -> deal_where($this -> _options['where']);
                        } else {
                                $where = $this -> _options['where'];
                        }
                        unset($this -> _options['where']);
                }
                return $where;
        }
        protected function parse_table()
        {
                $table = $this -> _table[1];
                if (!empty($this -> _options['table'])) {
                        if (is_numeric($this -> _options['table'])) {
                                $table = $this -> _table[$this -> _options['table']];
                        } else {
                                $table = $this -> _options['table'];
                        }
                        unset($this -> _options['table']);
                }
                return $table;
        }
        protected function deal_table($sql)
        {
                return preg_replace_callback('/#(\d+)/', array(__CLASS__, 'deal_table_callback'), $sql);
        }
        protected function deal_table_callback($tab)
        {
                return $this -> _table[$tab[1]];
        }
        public function sql($sql)
        {
                $this -> _options['sql'] = $sql;
                return $this;
        }
        public function where($where)
        {
                $this -> _options['where'] = $where;
                return $this;
        }
        public function order($order)
        {
                $this -> _options['order'] = $order;
                return $this;
        }
        public function table($table)
        {
                $this -> _options['table'] = $table;
                return $this;
        }
        public function field($field)
        {
                $this -> _options['field'] = $field;
                return $this;
        }
        public function limit($limit)
        {
                $this -> _options['limit'] = $limit;
                return $this;
        }
} [/php]

[ 本帖最后由 kakashilw 于 2009-3-5 13:08 编辑 ]

作者: kakashilw   发布时间: 2009-03-05

看下写的怎么样

作者: blankyao   发布时间: 2009-03-05

下来看看 谢谢分享

作者: E蜗牛   发布时间: 2009-03-05

支持了 :)学习

作者: abcnic1   发布时间: 2009-03-05

~runtime.php是怎么生成的啊?

作者: TankMe   发布时间: 2009-03-05

好,看看啊.

作者: wanchun0222   发布时间: 2009-03-05

支持一下!

作者: liexusong   发布时间: 2009-03-05

和ThinkPHP一样吧。。。

作者: zwws   发布时间: 2009-03-05

看看哈,

作者: dontlie   发布时间: 2009-03-05

挺强 的

作者: jinxikun001   发布时间: 2009-03-06

谢谢分享

作者: szrq   发布时间: 2009-03-06

看看,强~~

作者: yoofeng   发布时间: 2009-03-06

这么好的东西没人顶
我收藏了:lol:

作者: 啊丢   发布时间: 2009-03-09

没看见base类?model类?actio?接口?文件呢?

作者: 哈出出   发布时间: 2009-03-12

支持一下,这个用于学习很好

作者: aszx0413   发布时间: 2010-08-02