CI 묻고 답하기

제목 CI 에서 위지윅에디터( fckeditor )사용하기
글쓴이 아날로직 작성시각 2009/04/16 20:03:31
댓글 : 1 추천 : 0 스크랩 : 0 조회수 : 26778   RSS
fckeditor 는 2.6.4 버전입니다.
ci 버전은 1.7.1 버전입니다.

저는 .htaccess 설정에
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
이런룰을 적용해서 사용하고 있습니다. 그래서 fckeditor 는 걍 js 폴더에다 넣어버렸습니다.
위지윅에디터의 language 가 어차피 javascript 라...

우선 다운받은 fckeditor 를 압축풀어서 업로드 한 후에 fckeditor.php , fckeditor_php4.php , fckeditor_php5.php
세개의 파일을 system/application/libraries 안으로 이동시킵니다.
fckeditor.php 파일을 열어서
----------------------------------------------------------------------------
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
----------------------------------------------------------------------------
를 최상단에 넣습니다.

저는 환경이 php5 환경이라 fckeditor_php5.php 만을 수정하였습니다.
파일을 열어서 역시
----------------------------------------------------------------------------
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
----------------------------------------------------------------------------
를 최상단에 넣고 131번째 라인에
----------------------------------------------------------------------------
public function __construct( $instanceName )
{
$this->InstanceName = $instanceName ;
----------------------------------------------------------------------------
이부분을 아래와 같이 수정 해 줍니다. 아마 CI의 로더 특성때문에 인자를 배열로 전달해야 하는것 같습니다.
----------------------------------------------------------------------------
public function __construct( $array )
{
//$this->InstanceName = $instanceName ;
$this->InstanceName = $array['instanceName'] ;
----------------------------------------------------------------------------
그리고 view 파일의 입력창이 들어가야 될 부분에 (변수명은 관계없습니다) 라고 입력 해 주시고
controller 에서 아래와 같이 뿌려줍니다.

$this->load->library('form_validation');
$this->form_validation->set_rules('comment', '내용', 'trim|required|min_length[1]|xss_clean'); //이런 밸리데이션 체크가 있다고 가정합니다.

if($this->form_validation->run() == FALSE){
$data['subject']=set_value('subject'); //밸리데이션 통과 못했을때 입력값을 그대로 셋팅하는 부분입니다.

//이 아래부분이 fckeditor
$this->load->library('fckeditor',array('instanceName' => 'comment'));
$this->fckeditor->BasePath = base_url() . '/js/fckeditor/';
$this->fckeditor->ToolbarSet = 'Basic';
$this->fckeditor->Height = '400';
$this->fckeditor->Value = $this->mycommon->my_htmlspecialchars_decode(set_value('comment')); //밸리데이션 통과 못했을때 입력값을 그대로 셋팅하는 부분입니다.
//my_htmlspecialchars_decode <---- 이 함수는 php5 이상부터 사용가능한 htmlspecialchars_decode 함수를 흉내내서 개인적으로 쓰는 함수입니다. php4 환경에서 쓰일지도 몰라서.. 역할은 htmlspecialchars 의 반대역할입다.
$data['comment_area'] = $this->fckeditor->CreateHtml();
}else{
인서트 처리
}


만약 두개의 에디터가 필요하다면
$this->fckeditor->InstanceName = 'comment2';
$data['comment_area2'] = $this->fckeditor->CreateHtml();
이런식으로 사용합니다
 다음글 기본 셋팅을 끝냈습니다. (8)
 이전글 채팅 붙여놨습니다. (3)

댓글

송군 / 2011/09/12 20:54:28 / 추천 0
잘보았습니다. 많은 도움이 되었습니다( ^^ )