How to Set Up a ThinkPHP 6.x Project with Composer, ORM, and Bootstrap UI
This tutorial walks through configuring the development environment, installing Composer, ThinkPHP 6.x, ORM extensions, setting up database credentials, running the built‑in server, and integrating Bootstrap UI components with proper view configuration and sample code snippets.
First, configure the environment by adding the Composer China mirror, installing the ORM extension, Composer itself, and the required PHP PDO and MySQLi packages, then create a ThinkPHP 6.x project in the chosen directory.
composer config -g repo.packagist composer https://packagist.phpcomposer.com
composer require topthink/think-orm
apt install composer
apt install php-pdo php-mysqli
composer create-project topthink/think tp6demo
Next, rename the .example.env file to .env and edit it to provide the database username, password, and enable debug mode.
root 123456 student true
Start the built‑in development server (or configure a virtual host) with the command:
php think run // localhost:8000
To add a UI, copy the Bootstrap js and css directories into public/static , then adjust config/view.php to set the static template paths.
// template replacement output
'tp1_replace_string' => [
'__JS__' => '../static/js',
'__CSS__' => '../static/css',
],
Create a test method in a controller to verify the UI import, then install the view driver:
composer require topthink/think-view
Update config/view.php to use PHP templates:
'view_suffix' => 'php'
Create the template file view/index/test.php and include the Bootstrap CSS and JS assets in the <head> section:
<!-- 引入Bootstrap CSS -->
{css href="/static/css/bootstrap.min.css"}
{css href="/static/css/style.css"}
<!-- 移动设备优先 -->
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit-no">
Also add the JavaScript files at the end of the body :
<!-- 引入js文件 -->
{js href="/static/js/jquery-3.3.1.min.js"}
{js href="/static/js/bootstrap.bundle.min.js"}
Finally, a simple HTML snippet demonstrates a button and a table layout using Bootstrap classes:
<div class="container pt-5 mt-5">
<div class="row">
<div class="col-3">
<button class="btn btn-secondary">用户管理</button>
</div>
<div class="col-9">
<table class="table table-bordered">
<thead class="bg-light">
<tr><th>1</th><th>2</th><th>3</th><th>4</th><th>5</th></tr>
</thead>
</table>
</div>
</div>
</div>
php中文网 Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.