프로그램 개발서

[코드이그나이터] Custom Helper Function 모음 - Default 본문

Web

[코드이그나이터] Custom Helper Function 모음 - Default

rairen 2020. 5. 29. 15:33

코드이그나이터 헬퍼에 추가하여 사용하는 함수의 모음입니다.

대충 사용하던 코드 싹 지우고 새로 정리해서 1개씩 추가하는 중기도 하고요.

그러다 보니 버전으로 치면 아직 0.2밖에 되지 않네요 ㅠ

 

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * @Version 0.2
 * @last 2020.05.28
 * @Author Rairen
 */
if ( ! function_exists('view_load'))
{
	/**
	 * @param $views_path String views 폴더 내 경로
	 * @param $data mixed load되는 파일에서 쓸 데이터
	 */
	function view_load($views_path, $data = NULL)
	{
		$CI =& get_instance();
		$CI->load->view($views_path, $data);
	}
}
if ( ! function_exists('add_stylesheet'))
{
	/**
	 * 스타일시트 추가
	 *
	 * @param String|array $stylesheet 스타일시트태그(<link href=""/>)
	 * @param Int $order 출력순번
	 */
	function add_stylesheet($stylesheet, $order)
	{
		$ci_object =& get_instance();
		$links     = $ci_object->config->item('links');
		$is_merge  = TRUE;
		if (is_array($stylesheet))
		{
			for ($i = 0; $i < count($stylesheet); $i++)
			{
				foreach ($links as $link)
				{
					if ($link[1] == $stylesheet[$i])
					{
						$is_merge = FALSE;
						break;
					}
				}
				if ($is_merge)
				{
					$links[] = array($order, $stylesheet[$i]);
					
				}
			}
			$ci_object->config->set_item('links', $links);
		} else
		{
			foreach ($links as $link)
			{
				if ($link[1] == $stylesheet)
				{
					$is_merge = FALSE;
					break;
				}
			}
			if ($is_merge)
			{
				$links[] = array($order, $stylesheet);
				$ci_object->config->set_item('links', $links);
			}
		}
		
	}
}
if ( ! function_exists('add_javascript'))
{
	/**
	 * @param string|array $javascript 스크립트태그
	 * @param int $order
	 */
	function add_javascript($javascript, $order)
	{
		$ci_object =& get_instance();
		$scripts   = $ci_object->config->item('scripts');
		$is_merge  = TRUE;
		if (is_array($javascript))
		{
			for ($i = 0; $i < count($javascript); $i++)
			{
				foreach ($scripts as $script)
				{
					if ($script[1] == $javascript[$i])
					{
						$is_merge = FALSE;
						break;
					}
				}
				if ($is_merge)
				{
					$scripts[] = array($order, $javascript[$i]);
					$ci_object->config->set_item('scripts', $scripts);
				}
			}
		} else
		{
			foreach ($scripts as $script)
			{
				if ($script[1] == $javascript)
				{
					$is_merge = FALSE;
					break;
				}
			}
			if ($is_merge)
			{
				$scripts[] = array($order, $javascript);
				$ci_object->config->set_item('scripts', $scripts);
			}
		}
	}
}
if ( ! function_exists('breadcrumbs'))
{
	function breadcrumbs($breadcrumbs = array())
	{
		$breadcrumb_html = '';
		if (is_array($breadcrumbs) and count($breadcrumbs) > 0)
		{
			foreach ($breadcrumbs as $key => $breadcrumb)
			{

				if($breadcrumb['active'] == true){
					$breadcrumb_html .= '<li class="breadcrumb-item active" aria-current="page">' . $breadcrumb['name'] . '</li>';
				}
				else{
					if ($breadcrumb['link'] == TRUE and (isset($breadcrumb['href']) and ! empty($breadcrumb['href'])))
					{
						$breadcrumb_html .= '<li class="breadcrumb-item"><a href="' . $breadcrumb['href'] . '">' . $breadcrumb['name'] . '</a></li>';
					} else
					{
						$breadcrumb_html .= '<li class="breadcrumb-item"><a href="javascript:void(0);">' . $breadcrumb['name'] . '</a></li>';
					}
				}
			}
			return $breadcrumb_html;
		} else
		{
			return $breadcrumb_html;
		}
	}
}
if ( ! function_exists('head_title'))
{
	/**
	 * @param string $title 타이틀 명
	 */
	function head_title($title = '')
	{
		if (isset($title) and ! empty($title))
		{
			$CI         =& get_instance();
			$head_title = $CI->config->item('head_title');
			$CI->config->set_item('head_title', $title . ' | ' . $head_title);
		}
	}
}
if ( ! function_exists('encrypt'))
{
	/**
	 * @param string $password 비밀번호 문자열
	 * @param bool $raw_output 암호화 출력 형태 (binary|string)
	 * @param string $algorithm 암호화 알고리즘
	 * @return string 암호화 문자열
	 */
	function encrypt($password, $raw_output = FALSE, $algorithm = 'sha256')
	{
		return hash($algorithm, $password, $raw_output);
	}
}
if ( ! function_exists('alert_back'))
{
	/**
	 * @param string $message 메시지
	 */
	function alert_back($message = '')
	{
		$CI              =& get_instance();
		$data = array(
			'message' => $message
		);
		$CI->load->view('alert/back', $data);
	}
}
if ( ! function_exists('alert_replace'))
{
	/**
	 * @param string $message 메시지
	 * @param string $url 이동 주소
	 */
	function alert_replace($message = '', $url = '')
	{
		$CI =& get_instance();
		if (isset($url) and ! empty($url))
		{
			$data['url']     = $url;
			$data['message'] = $message;
			$CI->load->view('alert/replace', $data);
		} else
		{
			alert_back($message);
		}
		exit(0);
	}
}
if ( ! function_exists('alert_href'))
{
	/**
	 * @param string $message 메시지
	 * @param string $url 이동 주소
	 */
	function alert_href($message = '', $url)
	{
		$CI =& get_instance();
		if (isset($url) and ! empty($url))
		{
			$data['url']     = $url;
			$data['message'] = $message;
			$CI->load->view('alert/href', $data);
		} else
		{
			alert_back($message);
		}
		exit(0);
	}
}
if ( ! function_exists('alert_close'))
{
	/**
	 * @param string $message 메시지
	 */
	function alert_close($message = '')
	{
		$CI              =& get_instance();
		$data['message'] = $message;
		$CI->load->view('alert/close', $data);
		exit(0);
	}
}
if ( ! function_exists('menu_match'))
{
	/**
	 * @param string $match_menu_name 매칭할 메뉴 명칭
	 * @param int $depth 메뉴 단계(관리자는 $depth 2부터 매칭하자)
	 * @param string $class 매칭됬을 때 반환하는 클래스 명칭
	 * @return string 매칭 클랙스 반환
	 */
	function menu_match($match_menu_name, $depth = 1, $class = 'active')
	{
		if (isset($match_menu_name) and ! empty($match_menu_name))
		{
			$ci_object =& get_instance();
			$segment   = $ci_object->uri->segment($depth);
			if ($segment !== FALSE)
			{
				if ($match_menu_name == $segment)
				{
					return ' ' . $class . ' ';
				} else
				{
					return NULL;
				}
			} else
			{
				return NULL;
			}
		} else
		{
			return NULL;
		}
	}
}
반응형

'Web' 카테고리의 다른 글

Favicon HTML link Tag  (0) 2020.06.08
메타 태그  (0) 2020.06.08
[코드이그나이터] Custom Helper 모음 v0.1  (0) 2020.05.20
[Jquery][CodeIgniter] 회원가입 관련 코드 모음.  (0) 2020.05.20
mysqldump utf8 덤프 한글 문제  (0) 2020.04.28