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.

php Courses
php Courses
php Courses
How to Set Up a ThinkPHP 6.x Project with Composer, ORM, and Bootstrap UI

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>
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BootstrapComposerThinkPHP
php Courses
Written by

php Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.