(AdonisJs 4.0 Tutorial) 관리자 목록 보여주기
xyz/app/Controllers/Http/Mgmt/AdminController.js
파일을 생성한다.> cd xyz xyz> adonis make:controller Mgmt\Admin
'use strict' const Admin = use('App/Models/Admin') class AdminController { // 관리자 목록 async index ({view}) { const admins = await Admin.all() return view.render('mgmt.admin.index', { admins: admins.toJSON() }) } } module.exports = AdminController
xyz/resources/views/mgmt/base.edge
파일을 생성한다.<html> <head> <meta charset="utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <title>Adonis Tutorial</title> </head> <body> @!section('content') </body> </html>
xyz/resources/views/mgmt/admin/index.edge
파일을 생성한다.@layout('mgmt.base') @section('content') <div class="container"> <div class="page-header"> <h1>Administrator (관리자)</h1> </div> <table class="table table-striped table-hover table-condensed"> <tr> <th style="text-align: center">아이디</th> <th style="text-align: center">별명</th> <th style="text-align: center">수정/삭제</th> </tr> @each(admin in admins) <tr> <td style="text-align: center">{{ admin.userid }}</td> <td style="text-align: center">{{ admin.nick }}</td> <td style="text-align: center"> <a href="/mgmt/admin/chg_passwd_form/{{ admin.id }}" class="btn btn-default btn-xs" data-toggle="modal" data-target="#myModal">비밀번호변경</a> <a href="/mgmt/admin/update_form/{{ admin.id }}" class="btn btn-default btn-xs" data-toggle="modal" data-target="#myModal">수정</a> <button onclick="delete_admin('/mgmt/admin/delete/{{ admin.id }}')" class="btn btn-default btn-xs">삭제</button> </td> </tr> @endeach </table> </div> <script> function delete_admin(url) { var result = confirm("관리자를 정말로 삭제하시겠습니까?"); if( result == false ) return; location.href = url; } </script> @endsection
xyz/start/routes.js
에 다음을 추가한다.Route.group('mgmt', function () { Route.get('/admin', 'Mgmt/AdminController.index').as('mgmt_admin') }).prefix('/mgmt')
- 이제, 웹브라우저에서 http://localhost:3333/mgmt/admin 에 접속하면 관리자 목록을 볼 수 있을 것이다.
댓글
댓글 쓰기