search
Homephp教程PHP源码轻量web开发框架

轻量web开发框架

May 23, 2016 am 08:39 AM
php

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;]);
        }
    }
}

                   


                   

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.