0
点赞
收藏
分享

微信扫一扫

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​​

数据库配置:
Application\Common\Conf\config.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
Application\Home\Controller\IndexController.class.php

<?php
namespace Home\Controller;

use Think\Controller;

class IndexController extends Controller
{
public function index()
{
$List = D("List");
echo json_encode($List->select());
}
}

BaseController.class.php

<?php


namespace Home\Controller;
use Think\Controller;

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 .= "\n\n【★★★★★★★★★★★】";
$info .= "\n请求接口:".MODULE_NAME ."/".CONTROLLER_NAME."/".ACTION_NAME."";
$info .= "\n请求".'$_REQUEST'.":\n";
$info .= json_encode($_REQUEST);
$info .= "\n返回结果:\n";
$info .= json_encode($result)."\n";
$info .= "【★★★★★★★★★★★】\n";
\Think\log::record($info , 'INFO');
}

}
}

ListController.class.php


<?php
namespace Home\Controller;
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"]);

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

生活的意义就是你自己知道你要做什么,明确目标。没有目标,后面都是瞎扯!

新博客 ​​​https://www.VuejsDev.com​​ 用于梳理知识点



举报

相关推荐

0 条评论