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')

댓글

이 블로그의 인기 게시물

야마하 디지털 피아노 YDP-140

테이블위로 마우스 커서 이동시 색깔 변경하기

피아노 연습