1.多数据库访问
控制器
<?php
namespace app\controller;
use app\BaseController;
use think\facade\Db;
class Index extends BaseController
{
public function index()
{
$db1 = Db::connect('php2')->name('admin_role')->select();
$db = Db::name('admin')->select();
dump($db1,$db);
}
}
页面
2.配置路由
路由文件
<?php
use think\facade\Route;
Route::get('think', function () {
return 'hello,ThinkPHP6!';
});
Route::get('hello/:name', 'index/hello');
Route::rule('i','index');
页面
3.多应用模式
composer require topthink/think-multi-app //多应用模式扩展
后台管理系统
<?php
namespace app\admin\controller;
use app\BaseController;
class Index extends BaseController
{
public function index()
{
return '我是后台';
}
}
博客
<?php
namespace app\index\controller;
use app\BaseController;
use think\facade\Db;
class Index extends BaseController
{
public function index()
{
return '我是博客';
}
}