개발 Q&A

제목 컨트롤러에서 다른 컨트롤러를 호출해서 사용
카테고리 PHP
글쓴이 러기기기깅 작성시각 2017/09/25 12:25:40
댓글 : 5 추천 : 0 스크랩 : 0 조회수 : 10602   RSS

안녕하세요.

저번에도 질문을 드렸는데요.

관련 내용을 검색해봐도 이해가 잘 되지 않는 부분이 있어서 이렇게 질문을 드리게됐습니다..

<?php

class SendEmail extends CI_Controller{

	public function index(){

		
		$config['charset']   = "utf-8";
		$config['protocol']  = "smtp";
		$config['smtp_host'] = "ssl://smtp.gmail.com";
		$config['smtp_port'] = 465;
		$config['smtp_user'] = "id";
		$config['smtp_pass'] = "password";
		$config['smtp_timeout'] = 10;
		 
		$this->load->library('email', $config);
		$this->email->set_newline("\r\n");
		$this->email->set_mailtype('html');
		$this->email->clear();
		$this->email->from("TEST@email.com", "관리자");
		$this->email->to("test@test.com");
		$this->email->subject("TEST");
		$this->email->message("TEST");
		if (!$this->email->send())
		  echo "실패";
		else
		  echo "성공";

	}
}
?>

위와 같은 이메일 전송 컨트롤러가 있는데요.

다른 컨트롤러에서 게시물을 등록하는 버튼을 클릭시, 이메일 전송 컨트롤러를 호출해서 사용하고 싶습니다.

$email = new SendEmail();

echo $email->index(); 

와 같이 사용했을때는 동작을 하지 않아서.. 질문을 드립니다.

너무 초보자용 질문을 해서 죄송합니다. ㅜㅜ

 다음글 서버 apache, centos, php, mysql ... (4)
 이전글 코드이그나이터 객체 배열 질문드립니다! (5)

댓글

변종원(웅파) / 2017/09/25 13:38:16 / 추천 0
라이브러리로 만들어서 사용하시면 됩니다.
러기기기깅 / 2017/09/25 14:34:47 / 추천 0
<?php

	class SendEmail{

		public function index(){

		
			$config['charset']   = "utf-8";
			$config['protocol']  = "smtp";
			$config['smtp_host'] = "ssl://smtp.gmail.com";
			$config['smtp_port'] = 465;
			$config['smtp_user'] = "admin@test.com";
			$config['smtp_pass'] = "password";
			$config['smtp_timeout'] = 10;
			 
			$this->load->library('email', $config);
			$this->email->set_newline("\r\n");
			$this->email->set_mailtype('html');
			$this->email->clear();
			$this->email->from("admin@test.com", "관리자");
			$this->email->to("test@test.com");
			$this->email->subject("test");
			$this->email->message("test");
			$this->email->send();

	}
}
?>

답변해주셔서 감사합니다.

application/libraries에 이렇게 Sendemail.php로 저장한 다음

사용하고자 하는 controller에서

$this->load->library('sendemail');

$this->sendemail->index();

이렇게 사용했는데 오류가 뜹니다..ㅜㅜ

변종원(웅파) / 2017/09/25 15:01:28 / 추천 0
러기기기깅/ 어떤 오류가 뜨는데요?
러기기기깅 / 2017/09/25 15:09:26 / 추천 0

웅파/

이게 단편적으로 설명드리기가 복잡한데요.


		$this->load->library('sendemail');
		$this->sendemail->index();
		echo json_encode(array('status' => $status, 'msg' => "신청이 완료되었습니다."));

신청 버튼을 누르면 발생하는 액션에 저렇게 넣었습니다.

그리고 오류를 처리하는 곳에서

error:function(request, status, error){
				admin.alertDialogClose("알림", "알 수 없는 오류가 발생했습니다. 증상이 지속되면 관리자에게 문의 바랍니다.");
			}

이렇게 설정을 해뒀는데요.

위와 같은 오류메시지가 발생합니다..

변종원(웅파) / 2017/09/25 15:59:09 / 추천 0
$status를 받아오는 곳이 없네요. 보내주는 곳도 없고, 라이브러리에서 리턴하지도 않구요.