BOOK Module dispBookContentList
목록(List)과 모델(Model)
BOOK 모듈의 관리자 화면(back-end)에서 새로운 모듈(mid)을 생성하였다면, "Book 모듈 미리보기"와 같이 메뉴를 만들고 모듈(mid)을 연결하였을 것이다. 사용자는 모듈의 프론트 엔드에서 미리 설정된 기본 인덱스(index) 액션 이름을 모른다. 다만 메뉴에 연결된 링크를 클릭할 뿐이다.
XE코어는 사용자의 요청에 따라 링크로 연결될 모듈(mid)을 찾아본다. BOOK 모듈이다. 따라서 BOOK 모듈의 액션 명세서(module.xml)에서 프론트 엔드(front-end)의 기본 인덱스(index)로 설정된 dispBookcontentList 액션을 찾아 실행한다. 관리자 목록에서 "브라우저 제목"을 클릭해도 동일한 결과를 얻는다. 브라우저 제목은 {getUrl('','mid',$val->mid)} 와 같은 형태로 생성된 모듈(mid)의 모듈 아이디($mid) 값을 찾아 링크를 출발하기 때문이다.
★ XE코어의 모듈 중에는 모듈(module)이라는 이름의 모듈이 있고 혼동하기 않기 위해 앞으로 module 이라고 표기한다.
module 모델(Model) 객체를 생성한다는 것은 모듈을 관리하고 있는 module의 도움이 필요하다는 뜻이고, module 모델(Model)에서 사용하고 있는 맴버 변수와 맴버 메소드(하는 일)를 상속 받는다는 의미이다. 즉 URL로 요청 받은 모듈(mid)의 모듈 아이디($mid) 값을 module 모델의 메소드로 확인해 보겠다는 뜻이다. module 모델은 다음과 같은 결과값을 되돌려 준다. 되돌려 주는 방식은 $module_info에 모두 담아 보내준다. $module_info 변수의 내용을 확인해 보자.
$module_info stdClass Object ( [module_srl] => 3626 [module] => book [module_category_srl] => 2207 [layout_srl] => 2206 [use_mobile] => N [mlayout_srl] => 0 [menu_srl] => 3012 [site_srl] => 0 [mid] => book_example [skin] => default [mskin] => [browser_title] => 웹 관련 도서 [description] => [is_default] => N [content] => [mcontent] => [open_rss] => Y [header_text] => [footer_text] => [regdate] => 20110918225036 [_filter] => admin_insert )
module 모델에게 $mid를 힌트로 보여주었지만 module은 그것을 가지고 위와 같은 결과값을 얻는다. 모듈(mid)의 부모(module)는 누구이고, 그 자손 모듈(현재의 mid)의 고유 식별 번호($module_srl)는 무엇이라는 것을 알려주는 것이다.
결과적으로 모듈의 아이디(mid) 값을 알면 모듈의 고유 식별 번호($module_srl)를 알 수 있고 이 변수는 books 테이블에도 함께 저장해 두고 있다. 따라서 BOOK 모듈이 생성한 모듈(mid)이 입력해 둔 책들(books)의 목록을 찾는다는 것은 $module_srl의 값을 조건으로 books 테이블에 저장된 데이터를 확인해 보겠다는 것이고 dispBookContentList 함수는 그 결과값을 얻기 위해 MVC를 돌고 있는 것이다.
앞으로 이 모듈(웹 관련 도서)은 항상 같은 $module_srl를 가지고 다닌다. 책의 정보를 입력하면 books 테이블의 컬럼에도 매번 같은 $module_srl의 식별 번호를 저장할 것이다. 만약 새로운 모듈(mid)로 "교양도서"라고 생성하였다면 새로운 $module_srl이 생성되고 books 테이블의 컬럼에도 "교양도서"로 분류할 수 있는 같은 $module_srl의 데이터 row가 저장될 것이다.
1. 프론트 엔드 뷰(View)
프론트 엔드(front-end) 뷰(View)를 위한 설정 파일이다. 다음과 같이 작성하고 업로드 한다. 하는 일은 사용자 요청에 대한 결과를 출력할 스킨(skin) 파일을 찾아 두는 것이고, 모듈의 아이디(mid)를 이용해 $module_srl을 확인한다. 구해온 $module_srl은 항상 가지고 다닐 수 있도록 $module_info 변수에 세팅해 둔다. $module_info 변수는 모듈(mid)의 레이아웃이 무엇이지 메뉴는 어떤 것과 연결해서 사용하고 있는지 등의 모듈(mid)과 관련된 모든 정보를 확인하는 일이다.
book.view.php
<?php /** * @class bookView * @author XE스쿨 BOOK 모듈 만들기 예제 * @brief book 모듈의 view class **/ class bookView extends book { /** * @brief 초기화 **/ function init() { // module_srl이 있으면 미리 체크하여 존재하는 모듈이면 module_info 세팅 $module_srl = Context::get('module_srl'); if(!$module_srl && $this->module_srl) { $module_srl = $this->module_srl; Context::set('module_srl', $module_srl); } // module model 객체 생성 $oModuleModel = &getModel;('module'); // module_srl이 넘어오면 해당 모듈의 정보를 미리 구해 놓음 // 모듈의 브라우저 타이틀, 관리자, 레이아웃 등 xe_modules table의 값과 정보 if($module_srl) { $module_info = $oModuleModel->getModuleInfoByModuleSrl($module_srl); $this->module_info = $module_info; Context::set('module_info',$module_info); } // 스킨 경로를 미리 template_path 라는 변수로 설정함 // 스킨이 존재하지 않는다면 default로 변경 $template_path = sprintf("%sskins/%s/",$this->module_path, $this->module_info->skin); if(!is_dir($template_path)||!$this->module_info->skin) { $this->module_info->skin = 'default'; $template_path = sprintf("%sskins/%s/",$this->module_path, $this->module_info->skin); } $this->setTemplatePath($template_path); } /** * @brief 목록 **/ function dispBookContentList() { /** * 목록보기 권한 체크 (모든 권한은 ModuleObject에서 xml 정보와 module_info의 grant 값을 비교하여 미리 설정하여 놓음) **/ if(!$this->grant->access || !$this->grant->list) return $this->dispBookMessage('msg_not_permitted'); // module_srl 확인 $module_srl = Context::get('module_srl'); $args->module_srl = $module_srl; $args->page = Context::get('page'); // module model 객체 생성 $oModuleModel = &getModel;('module'); // book model에서 목록을 가져옴 $oBookModel = &getModel;('book'); $output = $oBookModel->getBookContentList($args); if(!$output->data) $output->data = array(); // $book_list 변수에 담는다. Context::set('book_list', $output->data); Context::set('page', $output->page); Context::set('page_navigation', $output->page_navigation); // template_file을 list.html로 지정 $this->setTemplateFile('list'); } /** * @brief 메세지 출력 **/ function dispBookMessage($msg_code) { $msg = Context::getLang($msg_code); if(!$msg) $msg = $msg_code; Context::set('message', $msg); $this->setTemplateFile('message'); } /** * @brief 오류메세지를 system alert로 출력하는 method * 특별한 오류를 알려주어야 하는데 별도의 디자인까지는 필요 없을 경우 페이지를 모두 그린후에 오류를 출력하도록 함 **/ function alertMessage($message) { $script = sprintf('<script type="text/javascript"> xAddEventListener(window,"load", function() { alert("%s"); } );</script>', Context::getLang($message)); Context::addHtmlHeader( $script ); } } ?>
모듈 명세서(module.xml)에서 <grants> 권한 설정으로 "목록"에 대해 "list"라는 name 속성을 설정했었다. "목록"은 템플릿에서 사용하는 언어일 뿐 중요한 키워드는 "list"라는 속성값이다. 관리자 권한 설정에서 list에 대해 "로그인 사용자" 등으로 권한을 제한하면 "guest"는 dispBookContentList() 메소드를 실행하지 못하고 중단 된다. 권한에 대한 안내 메시지는 같은 클래스 안의 맴버 메소드인 dispBookMessage() 메소드를 호출하면서 공통으로 설정되어 있는 권한 메시지 코드(msg_not_permitted)를 출력한다. 이후 입력과 삭제에서 추가되는 메소드에도 이와 같은 권한 설정을 확인하는 실행문이 포함된다. 이때 권한 설정을 확인하는 name 속성은 각각 모듈 명세서에 설정된 속성값에 따라 확인한다.
권한이 통과 되면 $module_srl을 확인하고 books 테이블에 접근하기 위해 자신(book)의 모델(Model)을 확장한다. 모델의 메소드(getBookContentList)를 호출하면서 요청인자 값으로 $module_srl을 함께 보내는 것이다. 즉 books 테이블에 가면 여러 줄(row)의 데이터가 있을 것인데 이때 조건으로 나의(mid) 모듈 식별 번호를 사용하라는 의미이다. 이렇게 받아온 결과값은 $output 변수에 대입해 둔다. 만약 결과값이 없다면 $output 변수가 배열이 아닐 수도 있을 것 같다. 따라서 일단 메소드 처리를 위해 빈 배열 형식이라도 변경해 둔다.
$output 값은 다차원 배열이다.(배열 확인은 보기(View)에서 한다...^^) 따라서 그 중에 실제로 책의 정보를 담고 있는 $output->data 값을 $book_list 라는 새로운 변수를 만들고 대입하여 URL에 세팅해서 보낸다. 목록 구성을 위해 필요한 $page_navigation 변수도 함께 세팅한다. 반환값을 처리하기 위한 사용자 스킨 파일은 "list"로 설정한다. 따라서 템플릿 파일의 경로를 찾아가 list.html 파일을 열고 $book_list 값을 넘겨 줄 것이다.
2. 모델(Model)
프론트 엔드 뷰(View) 파일에서 요청된 getBookContentList() 메소드를 실행한다. 모델은 데이터에 접근하기 위한 방법을 포함하는 MVC 패턴의 일부분이다. 메소드의 요청 인자($args)로 넘겨 받은 $module_srl을 가지고 XML 쿼리 문법으로 작성된 book 모듈.getBookContentList.xml 파일을 실행한다. 결과값은 $output 변수로 대입하여 반환한다.
book.model.php
<?php /** * @class bookModel * @author XE스쿨 BOOK 모듈 만들기 예제 * @brief book 모듈의 model class **/ class bookModel extends book { /** * @brief 초기화 **/ function init() { } // 목록 가져오기 function getBookContentList($args){ $output = executeQueryArray('book.getBookContentList', $args); return $output; } } ?>
3. XML 데이터 접근 쿼리
SELECT * FROM `xe_books` as books WHERE ( module_srl = 'module_srl');
DB에 저장된 데이터 row를 찾기 위한 SQL 쿼리를 XML 쿼리 언어로 변경하여 작성하는 것이다. 쿼리를 XML 언어로 작성하는 가장 큰 이유는 XE코어가 다양한 DBMS를 지원하기 때문이고 이때 쿼리 또한 DBMS에 따라 달라질 것이다. 아래 쿼리 언어는 MySQL의 데이터 타입에 매핑된 언어이고 따라서 이 글을 보는 학습자는 자신의 DBMS에 맞는 쿼리 언어를 작성하여야 한다. XML 쿼리 언어는 개발자 메뉴얼 p41에 자세히 기술되어 있다...^^
queries/getBookContentList.xml
<query id="getBookContentList" action="select"> <tables> <table name="books" /> </tables> <columns> <column name="*" /> </columns> <conditions> <condition operation="equal" column="module_srl" var="module_srl" /> </conditions> <navigation> <index var="sort_index" default="book_srl" order="desc" /> <list_count var="list_count" default="20" /> <page_count var="page_count" default="10" /> <page var="page" default="1" /> </navigation> </query> </pre> <h3>4. 사용자 스킨</h3> <p>프론트 엔드 뷰(View)의 결과물을 최종적으로 출력하는 템플릿 스킨 파일이다. CMS에서는 이것을 프론트 엔드(front-end)라고 표현한다. 즉 사용자 측면에서 가정 먼저 또는 요청에 대한 최종적인 결과물을 받아 보는 웹페이지를 말한다. 관리자 모듈 설정에서 상단 내용(header_text) 입력과 하단 내용(footer_text) 입력란이 있다. 이부분을 출력하는 내용 변수를 포함한 파일이 _header.html과 _footer.html 파일이다. 앞으로 나오게 될 스킨 파일의 위, 아래에는 항상 include문을 사용하여 이 문서 파일을 포함하도록 하자. _header.html 파일에는 스킨파일에서 사용될 CSS 파일도 포함하도록 한다.</p> <p><strong>skins/default/list.html</strong></p> <pre class="brush: xhtml; toolbar: false; gutter: false;"> <!--#include("_header.html")--> <h2>Book List : {$module_info->browser_title}</h2> <!-- 목록 --> <table border="0" class="bookTable"> <thead> <tr> <th>{$lang->no}</th> <th>{$lang->book_title}</th> <th>{$lang->book_author}</th> <th>{$lang->book_publisher}</th> <th>{$lang->book_price}</th> </tr> </thead> <tbody> <!--@foreach($book_list as $no => $book_info)--> <tr> <td>{$no}</td> <td><a href="{getUrl('book_srl', $book_info->book_srl,'act','dispBookContentView')}">{$book_info->book_title}</a></td> <td>{$book_info->book_author}</td> <td>{$book_info->book_publisher}</td> <td>{$book_info->book_price}</td> </tr> <!--@end--> </tbody> </table> <!-- 버튼 --> <div class="btn"> <a href="{getUrl('','mid',$mid)}" class="button green" title="{$lang->cmd_list}"><span>{$lang->cmd_list}</span></a> <a href="{getUrl('act','dispBookContentWrite')}" class="button red" title="{$lang->cmd_input}"><span>{$lang->cmd_input}</span></a> </div> <!-- 페이지 네비게이션 --> <div class="pagination a1"> <a href="{getUrl('page','','module_srl','')}" class="prevEnd">{$lang->first_page}</a> <!--@while($page_no = $page_navigation->getNextPage())--> <!--@if($page == $page_no)--> <strong>{$page_no}</strong> <!--@else--> <a href="{getUrl('page',$page_no,'module_srl','')}">{$page_no}</a> <!--@end--> <!--@end--> <a href="{getUrl('page',$page_navigation->last_page,'module_srl','')}" class="nextEnd">{$lang->last_page}</a> </div> <!--#include("_footer.html")--> </pre> <p>모듈(mid)에서 $module_info 변수는 항상 따라 다닌다. 따라서 {$module_info->browser_title} 형식의 XE 템플릿 구문으로 간단히 출력하여 사용할 수 있다.</p> <p>스킨에 사용된 언어는 모듈 언어팩(lang)에 설정된 $lang 변수를 찾아 출력한다. 넘겨 받은 $book_list 배열 변수는 foreach문을 이용해 키와 값으로 각각 접근하여 데이터의 갯수만큼 출력한다. 목록보기 버튼은 모듈의 $mid를 힌트로 다시 dispBookcontentList 액션을 실행하는 것을 의미하고, 입력에 사용된 버튼은 dispBookContentWrite 액션을 실행하는 것을 의미한다.</p> <p>함께 넘겨 받은 $page_navigation 변수를 이용해 목록의 리스트를 작성하고 남는 부분은 페이지 구성을 하게 된다.</p> <h3>5. 상단 내용(header_text) 출력</h3> <p>스킨의 상단과 하단에 출력하는 내용은 관리자 모듈 설정에서 상단 내용(header_text) 입력과 하단 내용(footer_text) 입력 값을 출력하는 것이다. 결과적으로 스킨 파일을 감싸는 최상위 DIV 역할을 한다. 상단 파일에는 스타일 적용을 위한 CSS 파일을 포함하도록 한다. BOOK 모듈의 스타일은 별로 설정해 둔 것이 없다. 예제를 위해 최소한의 table 스타일 속성만 설정되었다...^^</p> <p><strong>skins/default/_header.html</strong></p> <pre class="brush: xhtml; toolbar: false; gutter: false;"> <!--%import("css/book.css")--> <!--%import("css/pagination.css")--> {$module_info->header_text} <div class="book_content"> </pre> <h3>6. 하단 내용(footer_text)</h3> <p><strong>skins/default/_footer.html</strong></p> <pre class="brush: xhtml; toolbar: false; gutter: false;"> </div> {$module_info->footer_text} </pre> <h3>결과 확인</h3> <p>아직 입력된 내용이 없기 때문에 목록을 위한 제목외에는 출력되는 책의 정보가 없다...^^</p> <p>※ 스킨 파일의 skin.xml, message.html, CSS 파일에 대해서는 설명을 생략한다.</p> </div><!-- // XE노트 서브페이지 끝 --> </div> <div id="copyright"><p>Copyright ©2016 XE SCHOOL All rights reserved.</p></div> </div> </div><!-- // panel end --> </div><!-- // content end --> <div id="sidebar"> <div id="side"> <div class="bar_title top_radius bar_gradient shadow_black"> <span class="side_title">모듈</span> </div> <div class="side_content bottom_radius op shadow_black"> <ul class="lnb"> <li><a href="/xe/xenote_module_story">모듈의 기본 이해</a> <ul class="lnb_sub"> <li><a href="/xe/xenote_module_urls">XE의 URL 규칙</a></li><li><a href="/xe/xenote_module_form_db">폼(form)과 DB</a></li><li><a href="/xe/xenote_module_mvc">MVC 구조의 이해</a></li><li><a href="/xe/xenote_module_front_back_end">프론트엔드와 백엔드 뷰(View)</a></li><li><a href="/xe/xenote_module_admin_model">모듈 확장과 모델(Model)</a></li><li><a href="/xe/xenote_module_admin_controller_insert">입력 컨트롤러(Controller)</a></li><li><a href="/xe/xenote_module_admin_controller_delete">삭제 컨트롤러(Controller)</a></li><li><a href="/xe/xenote_module_admin_tab_menu">관리자 모듈 탭메뉴</a></li><li><a href="/xe/xenote_module_admin_grant_skininfo">액션 권한과 스킨정보</a></li> </ul> </li><li class="active"><a href="/xe/xenote_module_book_about">BOOK 모듈 만들기</a> <ul class="lnb_sub"> <li><a href="/xe/book_example">Book 모듈 미리보기</a></li><li><a href="/xe/xenote_module_book_config">모듈 설정 파일</a></li><li><a href="/xe/xenote_module_book_table_language">테이블 설치와 언어팩</a></li><li><a href="/xe/xenote_module_book_backend">백엔드 MVC</a></li><li class="active"><a href="/xe/xenote_module_book_contentlist">목록(List)과 모델</a></li><li><a href="/xe/xenote_module_book_contentview">보기(View)와 모델</a></li><li><a href="/xe/xenote_module_book_contentwrite">입력(Insert/Update) 컨트롤러</a></li><li><a href="/xe/xenote_module_book_contentdelete">삭제(Delete) 컨트롤러</a></li> </ul> </li><li><a href="/xe/xenote_module_about_bookmark">룰셋과 북마크 모듈 만들기</a> <ul class="lnb_sub"> <li><a href="/xe/xenote_module_bookmark_mvc">북마크 모듈의 MVC</a></li><li><a href="/xe/xenote_bookmark_registration">북마크 모듈 등록하기</a></li><li><a href="/xe/xenote_bookmark_adminlist">백엔드 북마크 목록보기</a></li><li><a href="/xe/xenote_bookmark_admininsert">백엔드 북마크 입력하기</a></li><li><a href="/xe/xenote_bookmark_admindelete">백엔드 북마크 삭제하기</a></li><li><a href="/xe/xenote_bookmark_list">프론트엔드 북마크 목록보기</a></li><li><a href="/xe/xenote_bookmark_insert">프론트엔드 북마크 입력하기</a></li><li><a href="/xe/xenote_bookmark_delete">프론트엔드 북마크 삭제하기</a></li> </ul> </li> </ul> </div> </div><!-- // side end --> </div><!-- // sidebar end --> </div><!-- // contentwrap end --> <div id="footer"> </div><!-- // footer end --> </div><!-- // container end --> </div><!-- // wrapper end --> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-27987546-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> <div id="waitingforserverresponse"></div> <script type="text/javascript" src="./addons/captcha/captcha.js"></script> <script type="text/javascript" src="./files/cache/js_filter_compiled/5e93526d838489c482d47d95cc345914.ko.compiled.js"></script> </body> </html> <!-- FILE ARCHIVED ON 07:13:08 Nov 30, 2016 AND RETRIEVED FROM THE INTERNET ARCHIVE ON 07:13:21 Aug 13, 2020. JAVASCRIPT APPENDED BY WAYBACK MACHINE, COPYRIGHT INTERNET ARCHIVE. ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C. SECTION 108(a)(3)). --> <!-- playback timings (ms): esindex: 0.015 PetaboxLoader3.resolve: 42.571 exclusion.robots.policy: 0.221 captures_list: 150.653 exclusion.robots: 0.231 LoadShardBlock: 109.62 (3) CDXLines.iter: 26.579 (3) PetaboxLoader3.datanode: 151.417 (4) load_resource: 139.781 RedisCDXSource: 6.633 -->