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


댓글

이 블로그의 인기 게시물

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

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

피아노 연습