Sails.js Tutorial : 관리자 목록 보여주기
xyz/api/controllers/mgmt/AdminController.js
파일을 생성한다.module.exports = { // 관리자 목록 index: function (req, res) { Admin.find().exec(function (err, admins) { res.locals.layout = 'mgmt/layout'; return res.view('mgmt/admin/index', { admins: admins }); }); }, }
xyz/views/mgmt/layout.ejs
파일을 생성한다.<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> <%- body %> </body> </html>
xyz/views/mgmt/admin/index.ejs
파일을 생성한다.<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> <% admins.forEach( function(admin) { %> <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> <% }); %> </table> </div> <script> function delete_admin(url) { var result = confirm("관리자를 정말로 삭제하시겠습니까?"); if( result == false ) return; location.href = url; } </script>
xyz/config/routes.js
을 다음처럼 수정한다.module.exports.routes = { '/': {view: 'homepage'}, 'get /mgmt' : 'mgmt/MainController.index', 'get /mgmt/admin' : 'mgmt/AdminController.index', };
- 이제, 웹브라우저에서 http://localhost:1337/mgmt/admin 에 접속하면 관리자 목록을 볼 수 있을 것이다.
댓글
댓글 쓰기