Home > Article > PHP Framework > ThinkPHP6 backend management system development: realizing backend functions
ThinkPHP6 backend management system development: realizing backend functions
Introduction:
With the continuous development of Internet technology and market demand, more and more enterprises and Organizations need an efficient, secure, and flexible backend management system to manage business data and conduct operational management. This article will use the ThinkPHP6 framework to demonstrate through examples how to develop a simple but practical backend management system, including basic functions such as permission control, data addition, deletion, modification and query.
php think module admin
Auth.php
and place it in the app/admin/middleware
directory. namespace appdminmiddleware; use thinkacadeSession; class Auth { public function handle($request, Closure $next) { // 判断用户是否登录 if (!Session::get('admin')) { return redirect(url('admin/login/index')); } return $next($request); } }
Then, register the middleware in the app/admin/middleware.php
file:
return [ 'Auth' => appdminmiddlewareAuth::class, ];
Finally, proceed in the route that requires permission control Definition of middleware, for example:
Route::group('admin', function () { Route::group('user', function () { Route::get('index', 'admin/user/index')->middleware('Auth'); }); });
User management:
First, we need to create a user-managed controller User.php
and place it in the app/admin/controller
directory Down.
namespace appdmincontroller; use thinkController; use appdminmodelUser as UserModel; class User extends Controller { public function index() { $userModel = new UserModel(); $users = $userModel->paginate(10); $this->assign('users', $users); return $this->fetch(); } public function create() { // 处理用户的创建逻辑 } public function edit($id) { // 处理用户的编辑逻辑 } public function delete($id) { // 处理用户的删除逻辑 } }
Then, create a user model User.php
and place it in the app/admin/model
directory.
namespace appdminmodel; use thinkModel; class User extends Model { // 表名 protected $table = 'users'; }
Finally, write the view code for the user list in the app/admin/view/user/index.html
file.
<table> <thead> <tr> <th>ID</th> <th>用户名</th> <th>邮箱</th> <th>操作</th> </tr> </thead> <tbody> {volist name="users" id="user"} <tr> <td>{$user.id}</td> <td>{$user.username}</td> <td>{$user.email}</td> <td> <a href="{:url('admin/user/edit', ['id'=>$user.id])}">编辑</a> <a href="{:url('admin/user/delete', ['id'=>$user.id])}">删除</a> </td> </tr> {/volist} </tbody> </table>
Article management:
Similarly, we can create an article management controller Article.php
and place it in the app/admin/controller
directory .
namespace appdmincontroller; use thinkController; use appdminmodelArticle as ArticleModel; class Article extends Controller { public function index() { $articleModel = new ArticleModel(); $articles = $articleModel->paginate(10); $this->assign('articles', $articles); return $this->fetch(); } public function create() { // 处理文章的创建逻辑 } public function edit($id) { // 处理文章的编辑逻辑 } public function delete($id) { // 处理文章的删除逻辑 } }
Similarly, create an article model Article.php
and place it in the app/admin/model
directory.
namespace appdminmodel; use thinkModel; class Article extends Model { // 表名 protected $table = 'articles'; }
Finally, write the view code for the article list in the app/admin/view/article/index.html
file, similar to the view code for user management.
Summary:
This article uses the ThinkPHP6 framework to develop a simple backend management system, and implements basic functions such as permission control, data addition, deletion, modification and query. Through this example, I hope readers can understand how to use ThinkPHP6 to quickly build a fully functional backend management system. Of course, in actual development, functions can be further improved and performance optimized to adapt to different business needs.
The above is the detailed content of ThinkPHP6 backend management system development: realizing backend functions. For more information, please follow other related articles on the PHP Chinese website!