zoukankan      html  css  js  c++  java
  • ThinkPHP 3.2.3

    说明手册
    https://www.kancloud.cn/manual/thinkphp/1706

    下载地址
    https://gitee.com/liu21st/thinkphp32

    thinkPHP 3.2.3 是从showdoc开源项目里面看到的,最新版的TP比较复杂,先看看这个老版本的。
    https://www.showdoc.com.cn/help?page_id=4087044677189279

    前台访问地址:
    http://localhost:8033/server/index.php/Home/Index/index

    数据库配置:
    ApplicationCommonConfconfig.php

    <?php
    return array(  
    	'DB_TYPE'=> 'mysql',  
    	'DB_HOST'=> 'localhost',  
    	'DB_NAME'=>'think_list',  
    	'DB_USER'=>'root',  
    	'DB_PWD'=>'123456',  
    	'DB_PORT'=>'3306',  
    	'DB_PREFIX'=>'think_',  
    	);  
    

    第一个 Controller
    ApplicationHomeControllerIndexController.class.php

    <?php
    namespace HomeController;
    
    use ThinkController;
    
    class IndexController extends Controller
    {
        public function index()
        {
            $List = D("List");
            echo json_encode($List->select());
        }
    }
    

    BaseController.class.php

    <?php
    
    
    namespace HomeController;
    use ThinkController;
    
    class BaseController extends Controller
    {
        /**
         * 返回json结果
         */
        protected function sendResult($array){
            if (isset($array['error_code'])) {
                $result['error_code'] = $array['error_code'] ;
                $result['error_message'] = $array['error_message'] ;
            }
            else{
                $result['error_code'] = 0 ;
                $result['data'] = $array ;
            }
    
            if ($this->is_local_debug > 0 ) {
                header('Access-Control-Allow-Origin: *');//允许跨域请求
                header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Connection, User-Agent, Cookie');
                header('Access-Control-Allow-Credentials: true');//允许跨域请求
            }
    
            echo json_encode($result);
    
            //如果开启API调试模式,则记录请求参数和返回结果
            if (C('API_LOG')) {
                $info = '';
                $info .= "
    
    【★★★★★★★★★★★】";
                $info .= "
    请求接口:".MODULE_NAME  ."/".CONTROLLER_NAME."/".ACTION_NAME."";
                $info .= "
    请求".'$_REQUEST'.":
    ";
                $info .= json_encode($_REQUEST);
                $info .= "
    返回结果:
    ";
                $info .= json_encode($result)."
    ";
                $info .= "【★★★★★★★★★★★】
    ";
                Thinklog::record($info , 'INFO');
            }
    
        }
    }
    

    ListController.class.php

    
    <?php
    namespace HomeController;
    class ListController extends BaseController
    {
        public function list()
        {
            $List = D("List"); // 实例化User对象
            $this->sendResult($List->select());
        }
    
        public function insert() {
            $insert = array(
                "text" => '123' ,
                "status" => '111'
            );
            $List = D("List")->add($insert);
            $result = array(
                "tip" => 'ok'
            );
            $this->sendResult($result);
        }
    
        public function update() {
            D("List")->where("id='1'")->save(array('text'=>'text111'));
            $this->sendResult(array('tip'=>"ok"));
        }
    }
    
    

    php token 的获取

    $headers = getallheaders();
    dump($headers["Token"]);
    
    ---------------------------------------------
    生活的意义并不是与他人争高下,而在于享受努力实现目标的过程,结果是对自己行动的嘉奖。
    ↑面的话,越看越不痛快,应该这么说:

    生活的意义就是你自己知道你要做什么,明确目标。没有目标,后面都是瞎扯!
  • 相关阅读:
    Django
    ionic创建项目报错Error: read ECONNRESET at _errnoException (util.js:992:11) at TLSWrap.onread (net.js:618:25)
    转《vue引入第三方js库》
    转《在浏览器中使用tensorflow.js进行人脸识别的JavaScript API》
    微信小程序自定义组件
    小程序中尽量少使用定时器
    解决小程序webview缓存机制
    小程序获取当前页面URL
    6s ios9.0平台 微信小程序的fixed定位兼容性问题
    如何使用nodejs快速搭建本地服务器
  • 原文地址:https://www.cnblogs.com/pengchenggang/p/14367042.html
Copyright © 2011-2022 走看看