로그인

검색

Extra Form
추천지수 5

오늘은 커뮤니티 한 곳에 새롭게 랜덤으로 게시글을 열람할 수 있는 랜덤게시글 모듈을 설치하고 적용했습니다. 그런데 선택된 게시글로 이동할때 스킨의 스크립트를 이용해서 이동을 하게 되다 보니 스킨을 로딩해야하고 하는 등의 과정 그리고 이로인해 모바일 등의 환경에서 원치하는 모습이 잠깐 연출되기도 합니다. 

 

차라리 스킨을 가져와서 해당 스킨에서 선택된 게시글로 이동하기 보다는 직접 선택된 게시글을 곧바로 php에서 이동해 버리면 빠르고 깔끔한 동작으로 이동이 되어서 오늘 코드를 추가해서 적용하였습니다.

 

 

/modules/randocument/randocument.view.php

위 파일을 열어보면 

 

    function dispRandocumentRand()
    {
        if(!$this->module_info->seleted_module_srl)
        {
            return new BaseObject(-1, '설정을 불러 올 수 없습니다.');
        }

        $oRandocumentModel = getModel('randocument');

        $output = $oRandocumentModel->getRandocumentToDocumentSrl($this->module_info->seleted_module_srl);
        if(!$output->toBool())
        {
            return $output;
        }

        if($output->data->document_srl)
        {
            $oDocument = getModel('document')->getDocument($output->data->document_srl);
            $link = $oDocument->getPermanentUrl();
            Context::set('getlink', $link);
        }
        else
        {
            Context::set('getlink', null);
        }
        if($this->module_info->test_mode === 'yes')
        {
            Context::set('document', $oDocument);
        }
        else
        {
            Context::set('document', null);
        }

        $this->setTemplateFile('rand');
    }
}

 

 

위와 같은 함수에서 랜덤으로 게시글 1개를 선택한 후 해당 게시글 정보를 모듈의 스킨을 불러와서 스킨에서 해당 게시글 정보를 기반으로 이동하게 되어있습니다.

 

 

 

 

 

화면 캡처 2022-03-30 180153.png

$this->setTemplateFile('rand');

스킨을 로딩하게 되는 코드 바로 위쪽에 바로 선택된 게시글로 php  header location 으로 이동해 버리는 코드를 추가했습니다.

 

if($link != null && $this->module_info->test_mode != 'yes')
{
if(Mobile::isMobileCheckByAgent() && $this->module_info->option_url_mobile)
{
header('Location: ' .$link .$this->module_info->option_url_mobile);
}
else if($this->module_info->option_url_pc)
{
header('Location: ' .$link .$this->module_info->option_url_pc);
}
else
{
header('Location: ' .$link );
}
}

 

위 코드가 추가되었습니다.

 

 

 

 

 

변경된 함수 전체는 아래와 같습니다.

 

function dispRandocumentRand()
{
if(!$this->module_info->seleted_module_srl)
{
return new BaseObject(-1, '설정을 불러 올 수 없습니다.');
}

$oRandocumentModel = getModel('randocument');

$output = $oRandocumentModel->getRandocumentToDocumentSrl($this->module_info->seleted_module_srl);
if(!$output->toBool())
{
return $output;
}

if($output->data->document_srl)
{
$oDocument = getModel('document')->getDocument($output->data->document_srl);
$link = $oDocument->getPermanentUrl();
Context::set('getlink', $link);
}
else
{
Context::set('getlink', null);
}
if($this->module_info->test_mode === 'yes')
{
Context::set('document', $oDocument);
}
else
{
Context::set('document', null);
}
if($link != null && $this->module_info->test_mode != 'yes')
{
if(Mobile::isMobileCheckByAgent() && $this->module_info->option_url_mobile)
{
header('Location: ' .$link .$this->module_info->option_url_mobile);
}
else if(!Mobile::isMobileCheckByAgent() && $this->module_info->option_url_pc)
{
header('Location: ' .$link .$this->module_info->option_url_pc);
}
else
{
header('Location: ' .$link );
}
}
$this->setTemplateFile('rand');
}

 

 

이렇게 코드를 추가하면 모듈의 스킨을 화면에 출력해서 해당 스킨에서 게시글로 이동하는 스크립트를 실행하고 하는 과정으로 진입하지 않고 뽑힌 랜덤 게시글로 곧바로 이동하여 불필요한 시간,과정 그리고 그 과정속에서 부자연 스러운 장면이 노출되는 그런 부분들을 방지 할 수 있게 되었습니다.

Who's 꿀팁관리소장

profile
라이믹스로 커뮤니티 사이트를 운영하는 비개발자 운영자 입니다.
파트너쉽 맺으실 사이트 운영자분 환영합니다.
2 추천
Atachment
첨부 '0'

라이믹스 팁(112)

라이믹스 운영과 사용에 관한 팁을 공유 합니다.

  1. read more
  2. read more
  3. Read More
  4. Read More
  5. 라이믹스 읽지 않은 쪽지(새쪽지) 표시해 주기 7

    Date2022.05.01 Category기능 Views508 Votes3
    Read More
  6. Read More
  7. Read More
  8. 라이믹스 게시판 목록에서 문서의 태그 출력해 주기 10

    Date2022.01.30 Category기능 Views2579 Votes5
    Read More
  9. Read More
  10. Read More
  11. Read More
  12. 라이믹스 설문조사 비회원참여를 막는 방법 2

    Date2021.12.05 Category기능 Views170 Votes2
    Read More
  13. Read More
  14. Read More
  15. 쿠키를 이용한 목록 스타일 변경 제공하기 1

    Date2021.11.20 Category기능 Views181 Votes4
    Read More
  16. Read More
  17. Read More
  18. 현재 읽고 있는 글의 목록 위치로 바로 가기 만들기 6

    Date2021.10.28 Category기능 Views182 Votes2
    Read More
  19. Read More
  20. Read More
  21. Read More
  22. Read More
  23. Read More
  24. Read More
  25. Read More
  26. Read More
  27. Read More
  28. Read More
  29. Read More
  30. 라이믹스 CK에디터 툴바의 링크 버튼 제거해 주기 2

    Date2021.09.04 Category운영 Views643 Votes3
    Read More
  31. Read More
  32. Read More
Prev 1 2 3 4 Next
/ 4