Home > php教程 > PHP源码 > body text

轻量web开发框架

PHP中文网
Release: 2016-05-23 08:39:06
Original
1734 people have browsed it

CoreThink是一套完全开源免费的WEB产品开发框架,追求简单、高效、卓越。可轻松实现支持多终端的WEB产品快速搭建、部署、上线。系统功能采用模块化、组件化、插件化等开放化低耦合设计,应用商城拥有丰富的功能模块、插件、主题,便于用户灵活扩展和二次开发。

代码包大于4M传不上去,可以在我们官网获取:www.corethink.cn


1. [图片] 1.jpg    

轻量web开发框架


2. [代码][PHP]代码

<?php
// +----------------------------------------------------------------------
// | OpenCMF [ Simple Efficient Excellent ]
// +----------------------------------------------------------------------
// | Copyright (c) 2014 http://www.php.cn/ All rights reserved.
// +----------------------------------------------------------------------
// | Author: jry <598821125@qq.com>
// +----------------------------------------------------------------------
namespace Home\Controller;
use Common\Controller\CommonController;
/**
 * 前台公共控制器
 * 为防止多分组Controller名称冲突,公共Controller名称统一使用模块名
 * @author jry <598821125@qq.com>
 */
class HomeController extends CommonController {
    /**
     * 初始化方法
     * @author jry <598821125@qq.com>
     */
    protected function _initialize() {
        // 系统开关
        if (!C(&#39;TOGGLE_WEB_SITE&#39;)) {
            $this->error(&#39;站点已经关闭,请稍后访问~&#39;);
        }

        // 获取所有模块配置的用户导航
        $mod_con[&#39;status&#39;] = 1;
        $_user_nav_main = array();
        $_user_nav_list = D(&#39;Admin/Module&#39;)->where($mod_con)->getField(&#39;user_nav&#39;, true);
        foreach ($_user_nav_list as $key => $val) {
            if ($val) {
                $val = json_decode($val, true);
                if ($val[&#39;main&#39;]) {
                    $_user_nav_main = array_merge($_user_nav_main, $val[&#39;main&#39;]);
                }
            }
        }

        // 监听行为扩展
        \Think\Hook::listen(&#39;corethink_behavior&#39;);

        $this->assign(&#39;meta_keywords&#39;, C(&#39;WEB_SITE_KEYWORD&#39;));
        $this->assign(&#39;meta_description&#39;, C(&#39;WEB_SITE_DESCRIPTION&#39;));
        $this->assign(&#39;_new_message&#39;, cookie(&#39;_new_message&#39;));          // 获取用户未读消息数量
        $this->assign(&#39;_user_auth&#39;, session(&#39;user_auth&#39;));              // 用户登录信息
        $this->assign(&#39;_user_nav_main&#39;, $_user_nav_main);               // 用户导航信息
        $this->assign(&#39;_user_center_side&#39;, C(&#39;USER_CENTER_SIDE&#39;));      // 用户中心侧边
        $this->assign(&#39;_user_login_modal&#39;, C(&#39;USER_LOGIN_MODAL&#39;));      // 用户登录弹窗
        $this->assign(&#39;_home_public_layout&#39;, C(&#39;HOME_PUBLIC_LAYOUT&#39;));  // 页面公共继承模版
    }

    /**
     * 用户登录检测
     * @author jry <598821125@qq.com>
     */
    protected function is_login() {
        //用户登录检测
        $uid = is_login();
        if ($uid) {
            return $uid;
        } else {
            if (IS_AJAX) {
                $return[&#39;status&#39;]  = 0;
                $return[&#39;info&#39;]    = &#39;请先登录系统&#39;;
                $return[&#39;login&#39;] = 1;
                $this->ajaxReturn($return);
            } else {
                redirect(U(&#39;User/User/login&#39;, null, true, true));
            }
        }
    }

    /**
     * 设置一条或者多条数据的状态
     * @param $script 严格模式要求处理的纪录的uid等于当前登陆用户UID
     * @author jry <598821125@qq.com>
     */
    public function setStatus($model = CONTROLLER_NAME, $script = true) {
        $ids    = I(&#39;request.ids&#39;);
        $status = I(&#39;request.status&#39;);
        if (empty($ids)) {
            $this->error(&#39;请选择要操作的数据&#39;);
        }
        $model_primary_key = D($model)->getPk();
        $map[$model_primary_key] = array(&#39;in&#39;,$ids);
        if ($script) {
            $map[&#39;uid&#39;] = array(&#39;eq&#39;, is_login());
        }
        switch ($status) {
            case &#39;forbid&#39; :  // 禁用条目
                $data = array(&#39;status&#39; => 0);
                $this->editRow(
                    $model,
                    $data,
                    $map,
                    array(&#39;success&#39;=>&#39;禁用成功&#39;,&#39;error&#39;=>&#39;禁用失败&#39;)
                );
                break;
            case &#39;resume&#39; :  // 启用条目
                $data = array(&#39;status&#39; => 1);
                $map  = array_merge(array(&#39;status&#39; => 0), $map);
                $this->editRow(
                    $model,
                    $data,
                    $map,
                    array(&#39;success&#39;=>&#39;启用成功&#39;,&#39;error&#39;=>&#39;启用失败&#39;)
                );
                break;
            case &#39;hide&#39; :  // 隐藏条目
                $data = array(&#39;status&#39; => 2);
                $map  = array_merge(array(&#39;status&#39; => 1), $map);
                $this->editRow(
                    $model,
                    $data,
                    $map,
                    array(&#39;success&#39;=>&#39;隐藏成功&#39;,&#39;error&#39;=>&#39;隐藏失败&#39;)
                );
                break;
            case &#39;show&#39; :  // 显示条目
                $data = array(&#39;status&#39; => 1);
                $map  = array_merge(array(&#39;status&#39; => 2), $map);
                $this->editRow(
                   $model,
                   $data,
                   $map,
                   array(&#39;success&#39;=>&#39;显示成功&#39;,&#39;error&#39;=>&#39;显示失败&#39;)
                );
                break;
            case &#39;recycle&#39; :  // 移动至回收站
                $data[&#39;status&#39;] = -1;
                $this->editRow(
                    $model,
                    $data,
                    $map,
                    array(&#39;success&#39;=>&#39;成功移至回收站&#39;,&#39;error&#39;=>&#39;删除失败&#39;)
                );
                break;
            case &#39;restore&#39; :  // 从回收站还原
                $data = array(&#39;status&#39; => 1);
                $map  = array_merge(array(&#39;status&#39; => -1), $map);
                $this->editRow(
                    $model,
                    $data,
                    $map,
                    array(&#39;success&#39;=>&#39;恢复成功&#39;,&#39;error&#39;=>&#39;恢复失败&#39;)
                );
                break;
            case &#39;delete&#39;  :  // 删除条目
                $result = D($model)->where($map)->delete();
                if ($result) {
                    $this->success(&#39;删除成功,不可恢复!&#39;);
                } else {
                    $this->error(&#39;删除失败&#39;);
                }
                break;
            default :
                $this->error(&#39;参数错误&#39;);
                break;
        }
    }

    /**
     * 对数据表中的单行或多行记录执行修改 GET参数id为数字或逗号分隔的数字
     * @param string $model 模型名称,供M函数使用的参数
     * @param array  $data  修改的数据
     * @param array  $map   查询时的where()方法的参数
     * @param array  $msg   执行正确和错误的消息
     *                       array(
     *                           &#39;success&#39; => &#39;&#39;,
     *                           &#39;error&#39;   => &#39;&#39;,
     *                           &#39;url&#39;     => &#39;&#39;,   // url为跳转页面
     *                           &#39;ajax&#39;    => false //是否ajax(数字则为倒数计时)
     *                       )
     * @author jry <598821125@qq.com>
     */
    final protected function editRow($model, $data, $map, $msg) {
        $id = array_unique((array)I(&#39;id&#39;,0));
        $id = is_array($id) ? implode(&#39;,&#39;,$id) : $id;
        //如存在id字段,则加入该条件
        $fields = D($model)->getDbFields();
        if (in_array(&#39;id&#39;, $fields) && !empty($id)) {
            $where = array_merge(
                array(&#39;id&#39; => array(&#39;in&#39;, $id )),
                (array)$where
            );
        }
        $msg = array_merge(
            array(
                &#39;success&#39; => &#39;操作成功!&#39;,
                &#39;error&#39;   => &#39;操作失败!&#39;,
                &#39;url&#39;     => &#39; &#39;,
                &#39;ajax&#39;    => IS_AJAX
            ),
            (array)$msg
        );
        $result = D($model)->where($map)->save($data);
        if ($result != false) {
            $this->success($msg[&#39;success&#39;], $msg[&#39;url&#39;], $msg[&#39;ajax&#39;]);
        } else {
            $this->error($msg[&#39;error&#39;], $msg[&#39;url&#39;], $msg[&#39;ajax&#39;]);
        }
    }
}
Copy after login

                   


                   

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template