最近我写了一个自动生成模型的工具, 请大家看看这个模型中还有哪些需要完善

浏览:1409 发布日期:2014/01/22 分类:技术分享 关键字: 代码生成器
因为验证是在HTML中, 所以模型中没加验证
另外: 根据3.2的规范, 生成的模型代码中不需要表前缀, 也就是说配置文件的要设为
'DB_PREFIX'=>'',

以下是代码生成器软件图片:





以下为生成的代码,支持左右联接等, 请大家看看生成的MODEL有什么地方需要再完善<?php

namespace Common\Model;

use Think\Model;

class HelpsModel extends Model {

    /**
     * 由主键查看某条记录是否存在
     * 输入主键的值
     * 返回值: 布尔型
     */
    public function get_isexist_byid($id) {
        $model = D ( 'system_helps' );
        $map ['system_helps.id'] = $id;
        $result = $model->where ( $map )->select ();

        if (empty ( $result )) {
            $result = false;
        } else {
            $result = true;
        }

        return $result;
    }

    /**
     * 由条件查看某些记录是否存在
     * 输入查询条件数组
     * 返回值: 布尔型
     */
    public function get_isexist($map) {
        $model = D ( 'system_helps' );
        $result = $model->where ( $map )->select ();

        if (empty ( $result )) {
            $result = false;
        } else {
            $result = true;
        }

        return $result;
    }

    /**
     * 由条件统计记录个数
     * 输入查询条件数组
     * 返回值: 布尔型
     */
    public function get_rows_count($map) {
        $model = D ( 'system_helps' );
        $rowsCount = $model->field ( 'count(*) as rowsCount' )->where ( $map )->select ();
        $rowsTotal = $rowsCount [0] ['rowsCount'];
        return $rowsTotal;
    }

    /**
     * 由主键得到表的一条记录
     * 输入主键的值
     * 返回值: 数组或布尔型false
     */
    public function get_info_byid($id) {
        $model = D ( 'system_helps' );
        $map ['system_helps.id'] = $id;
        $result = $model->field ( 'system_helps_cates_o1.title as c_title, system_helps.*' )->join ( ' LEFT JOIN system_helps_cates system_helps_cates_o1 on system_helps_cates_o1.cid = system_helps.cid' )->where ( $map )->select ();

        if (empty ( $result )) {
            $result = false;
        } else {
            $result [0] ['text'] = $result ['0'] ['title'];
            $result [0] ['isshow_title'] = get_lang_boolenTitle_bycode ( $result ['0'] ['isshow'] );
            $result [0] ['isuse_title'] = get_lang_boolenTitle_bycode ( $result ['0'] ['isuse'] );
            $result [0] ['addTime_title'] = get_lang_timeTitle_byTime ( $result ['0'] ['addTime'] );
            $result [0] ['editTime_title'] = get_lang_timeTitle_byTime ( $result ['0'] ['editTime'] );
        }

        return $result [0];
    }

    /**
     * 由条件得到表的一条记录
     * 输入查询条件数组
     * 返回值: 数组或布尔型false
     */
    public function get_info($map) {
        $model = D ( 'system_helps' );
        $result = $model->field ( 'system_helps_cates_o1.title as c_title, system_helps.*' )->join ( ' LEFT JOIN system_helps_cates system_helps_cates_o1 on system_helps_cates_o1.cid = system_helps.cid' )->where ( $map )->select ();

        if (empty ( $result )) {
            $result = false;
        } else {
            $result [0] ['text'] = $result ['0'] ['title'];
            $result [0] ['isshow_title'] = get_lang_boolenTitle_bycode ( $result [0] ['isshow'] );
            $result [0] ['isuse_title'] = get_lang_boolenTitle_bycode ( $result [0] ['isuse'] );
            $result [0] ['addTime_title'] = get_lang_timeTitle_byTime ( $result [0] ['addTime'] );
            $result [0] ['editTime_title'] = get_lang_timeTitle_byTime ( $result [0] ['editTime'] );
        }

        return $result [0];
    }

    /**
     * 由条件得到列表数组
     * 输入查询条件数组
     * 返回值: 数组或布尔型false
     */
    public function get_list($p, $PerPage, $map, $order) {
        $model = D ( 'system_helps' );
        if (strlen ( $order ) > 0) {
            $rows = $model->field ( 'system_helps_cates_o1.title as c_title, system_helps.*' )->join ( ' LEFT JOIN system_helps_cates system_helps_cates_o1 on system_helps_cates_o1.cid = system_helps.cid' )->where ( $map )->page ( $p, $PerPage )->order ( $order )->select ();
        } else {
            $rows = $model->field ( 'system_helps_cates_o1.title as c_title, system_helps.*' )->join ( ' LEFT JOIN system_helps_cates system_helps_cates_o1 on system_helps_cates_o1.cid = system_helps.cid' )->where ( $map )->page ( $p, $PerPage )->select ();
        }
        $rowsCount = $model->field ( 'count(*) as rowsCount' )->where ( $map )->select ();
        $rowsTotal = $rowsCount [0] ['rowsCount'];
        if ($rowsTotal > 0) {
            for($i = 0; $i < count ( $rows ); $i ++) {
                $rows [$i] ['text'] = $rows [$i] ['title'];
                $rows [$i] ['isshow_title'] = get_lang_boolenTitle_bycode ( $rows [$i] ['isshow'] );
                $rows [$i] ['isuse_title'] = get_lang_boolenTitle_bycode ( $rows [$i] ['isuse'] );
                $rows [$i] ['addTime_title'] = get_lang_timeTitle_byTime ( $rows [$i] ['addTime'] );
                $rows [$i] ['editTime_title'] = get_lang_timeTitle_byTime ( $rows [$i] ['editTime'] );
            }
            $resultArray = array ();
            $resultArray ['total'] = $rowsTotal;
            $resultArray ['rows'] = $rows;
        } else {
            $resultArray = false;
        }
        return $resultArray;
    }

    /**
     * 向表插入记录
     * 输入数组
     * 返回值: 如果主键是自动增长型 成功后返回值就是最新插入的值
     */
    public function add($map) {
        $model = D ( 'system_helps' );
        $result = $model->add ( $map );
        return $result;
    }

    /**
     * 按主键更改表记录
     * 输入主键和要插入的数组
     * 返回值: 更改记录个数 整型
     */
    public function edit_byid($id, $table) {
        $model = D ( 'system_helps' );
        $map ['system_helps.id'] = $id;
        $result = $model->where ( $map )->save ( $table );
        return $result;
    }

    /**
     * 按条件更改表记录
     * 输入条件数组和要插入的数组
     * 返回值: 更改记录个数 整型
     */
    public function edit($map, $table) {
        $model = D ( 'system_helps' );
        $result = $model->where ( $map )->save ( $table );
        return $result;
    }

    /**
     * 按主键删除表记录
     * 输入主键和要插入的数组
     * 返回值: 删除记录个数 整型
     */
    public function delete_byid($id) {
        $model = D ( 'system_helps' );
        $map ['system_helps.id'] = $id;
        $result = $model->where ( $map )->delete ( );
        return $result;
    }

    /**
     * 按条件删除表记录
     * 输入条件数组
     * 返回值: 删除记录个数 整型
     */
    public function delete($map) {
        $model = D ( 'system_helps' );
        $result = $model->where ( $map )->delete ( );
        return $result;
    }
}
注意: 因为现在的生成器还不完善, 等完善后我会发布出来, 如果哪们同学想提前尝鲜或协助我测试,可联系我索取当前并不完善的版本.
补充: 此生成器我是用NET 开发的, 需要在您的机器上安装NET frameWORK 4.0

我的QQ: 9411526
有什么建议欢迎到我的网站上交流: http://www.abis.com.cn/forum-51-1.html
最终版本也将在上面的地址上首发
最佳答案
评论( 相关
后面还有条评论,点击查看>>