5. Action

Action 소개

XpressEngine의 모든 입력과 출력은 index.php를 통해서 이루어집니다.

입력된 요청을 분석후 대상 Module을 찾은 후 그 Module의 어떤 동작을 해야 하는지 결정하는 것이 Action입니다.
보통 이 동작을 결정하는 Action은 Request Argument의 $act 변수값을 이용합니다..

 

이 Action에 대한 선언은 모듈의 ./conf/module.xml에 정의되어 있습니다.

 

  1. <?xml version="1.0" encoding="utf-8"?>
    <module>
     <grants />
  2.  <permissions />
     <actions>
      <action name="dispFileAdminList" type="view" admin_index="true" standalone="true" />
      <action name="dispFileAdminConfig" type="view" standalone="true" />
      <action name="procFileUpload" type="controller" standalone="true" />
      <action name="procFileDelete" type="controller" standalone="true" />
      <action name="procFileDownload" type="controller" standalone="true" />
      <action name="procFileAdminDeleteChecked" type="controller" standalone="true" />
      <action name="procFileAdminInsertConfig" type="controller" standalone="true" />
     </actions>
    </module>

 

Action 이용

Action은 $act 라는 변수를 통해서 호출할 수 있습니다.

호출은 GET/ POST/ JSON/ XMLRPC 어떤 경우에도 act라는 이름을 이용하게 됩니다.

 

예) editor 모듈의 dispEditorPopup() 호출 (./modules/editor/editor.view.php)

  1. ?module=editor&act=dispEditorPopup&editor_sequence=1&component=image_editor

 

 

Action Forward

일반적으로 XE의 Action은 모듈에 귀속됩니다.

즉 별다른 지시가 없을 경우 $act 변수에 의해 Action이 호출되면 현재 동작중인 모듈의 Action으로 인정이 되어 실행됩니다.

하지만 경우에 따라서 현재 동작중인 모듈이 아닌 다른 모듈의 Action이 호출될 경우가 있습니다.

 

대표적인 예가 RSS 입니다.

$act = rss 는 게시판모듈에서 정의된 Action이 아니지만 Action Forward 기능을 통해 호출되어 실행이 됩니다.

Action Forward는 모듈 독립적인 기능을 수행하기를 원할때 사용할 수 있습니다.

 

  1. ?mid=board&act=rss

 

위와 같은 요청의 경우 board 라는 mid를 찾게 되고 이 mid가 게시판 모듈의 mid일 경우 rss라는 Action이 없습니다.

이럴 경우 XE는 Action Forward 등록된 것중에 rss라는 것이 있는지 찾게 됩니다.

rss라는 Action은 RSS모듈의 View type으로 DB에 등록이 되어 있어서 XE는 board라는 mid의 정보를 모두 설정하고 나서 RSS 모듈의 View 객체를 생성해서 rss method를 실행하게 됩니다.

 

이 Action Forward는 현재 요청된 모듈의 레이아웃이나 정보를 유지한채 다른 동작을 원할 경우 필요합니다.

다른 예로 친구 목록을 보는 Action은 Communication 모듈의 dispCommunicationFriend 라는 Action으로 동작을 합니다.

이 Action은 현재 보고 있는 모듈의 레이아웃등을 그대로 유지한채 내용을 친구 목록으로 대체합니다.

 

즉 컨텐츠 영역을 약속된 Action에 따라서 바꾸어서 출력할 수도 있고 요청된 모듈의 정보를 바탕으로 다른 결과를 유도할 수도 있는 기능입니다.