Adonis Tutorial : 관리자 목록 보여주기
xyz/app/Http/Controllers/Mgmt/AdminController.js
파일을 생성한다.'use strict' const Admin = use('App/Model/Admin') // 관리자 목록 class AdminController { * index (request, response) { const admins = yield Admin.all() yield response.sendView('mgmt/admin/index', { admins: admins.toJSON() }) } } module.exports = AdminController
xyz/resources/views/mgmt/base.njk
파일을 생성한다.<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" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <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" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> <title>Adonis Tutorial</title> </head> <body> {% block content %}{% endblock %} </body> </html>
xyz/resources/views/mgmt/admin/index.njk
파일을 생성한다.{% extends '../base' %} {% block 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> {% for 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> {% endfor %} </table> </div> {% endblock %} <script> function delete_admin(url) { var result = confirm("관리자를 정말로 삭제하시겠습니까?"); if( result == false ) return; location.href = url; } </script>
xyz/app/Http/routes.js
에 다음을 추가한다.Route.group('mgmt', function () { Route.get('/admin', 'Mgmt/AdminController.index').as('mgmt_admin') }).prefix('/mgmt')
- 이제, 웹브라우저에서 http://localhost:3333/mgmt/admin 에 접속하면 관리자 목록을 볼 수 있을 것이다.
댓글
댓글 쓰기