CI 묻고 답하기

제목 image_lib 를 이용한 helper
카테고리 CI 2, 3
글쓴이 강동원 작성시각 2016/12/19 13:23:50
댓글 : 5 추천 : 0 스크랩 : 0 조회수 : 13822   RSS
// controller

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Thumb extends CI_Controller {

 	function __construct()
	{
		parent::__construct();

	}

	function thumb_test() {
		$this->load->helper('thumb');
		make_thumb();
	}
}
//helper
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

function make_thumb(){

	$config['image_library'] = 'gd2';
	$config['source_image']	= './static/upload/image/original/148207021533.jpg';
	$config['create_thumb'] = TRUE;
	$config['maintain_ratio'] = TRUE;
	$config['width']	= 75;
	$config['height']	= 50;
	$config['thumb_maker'] = "thumb_";

	//print_r($config);
	
	$this->load->library('image_lib', $config);

	//$this->image_lib->initialize($config);
	$this->image_lib->resize();
	//$this->image_lib->clear();	
}

 

image_lib 를 이용해서 help를 만드려고 합니다. 

$this->load->library('image_lib', $config); 이부분에서 500에러가 납니다.

이미지 섬네일 생성하는 부분을 helper를 이용하지 않고 controll에서 바로 실행할때는 아무런 문제가 없는데 helper를 이용하니 문제가 생기네요. 고수님들 답변 좀 부탁드려요 (__ );

 다음글 PC & Mobile 코드 공용화를 어느수준까지... (5)
 이전글 검색 시 큰따움표 처리 어떻게 하나요? (1)

댓글

한대승(불의회상) / 2016/12/19 13:41:26 / 추천 0

library 로드하는 방법이 틀렸습니다.

아래처럼 바꾸세요.

$this->load->library('image_lib');
$this->image_lib->initialize($config);

 

강동원 / 2016/12/19 15:54:45 / 추천 0
알려 주신것과 같이 해 봐도 계속 500 에러가 뜨네요.
강동원 / 2016/12/19 15:59:21 / 추천 0

helper 파일에 있는 내용을 그대로 cotroller에 가져다 넣으면 잘 실행이 되거든요.

helper에만 들어가면 오류가 발생하네요

변종원(웅파) / 2016/12/20 09:46:39 / 추천 0
헬퍼는 ci 제어권 바깥입니다. 인스턴스 선언해서 사용하셔야 합니다. 매뉴얼에서 instance 검색해보세요.
강동원 / 2016/12/21 15:29:46 / 추천 0
번번히 도움 주셔서 고맙습니다. 즐거운 크리스마스 되시길 바랍니다.