CI 서브 폴더 사용CI 서브 폴더 사용

Posted at 2021. 2. 17. 15:41 | Posted in PHP/CodeIgniter
반응형

cikorea.net/bbs/view/qna?idx=12166

 

CI 서브디렉토리에 배포 질문이요.~~

도와 주세요..  ㅠㅠ   호스팅받아 운영중인 시스템이있는데요 그 안에 서브로 디렉토리를 만들어 CI를 설치를 했더니 계속 404만 뜨네요.  예 : 운영 : www.test.com CI를 설치하여 별도로 운영하고

cikorea.net

 

.htaccess 기본 설정

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond $1 !^(index\.php|images|captcha|data|include|uploads|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

 

 

.htaccess 기본 설정 변경

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond $1 !^(/프로젝트_디렉토리명/index\.php|images|captcha|data|include|uploads|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /프로젝트_디렉토리명/index.php/$1 [L]
</IfModule>
반응형
//

[CodeIgniter] _rmap을 이용한 화면 상단, 하단 레이어 고정[CodeIgniter] _rmap을 이용한 화면 상단, 하단 레이어 고정

Posted at 2020. 2. 12. 17:31 | Posted in PHP/CodeIgniter
반응형




■ 코드이그나이터에서 헤더 푸터 레이아웃 지정





코드이그나이터의 함수요청 리다이렉트를 통해


웹 페이지 상단(헤더), 하단(푸터)를 고정적으로 노출 시키려고 한다.


기본적으로 코드이그나이터를 세팅하면 보게되는


Welcome to CodeIgniter! 페이지에


헤더와 푸터를 나타내 보자




# 컨트롤럴 소스코드

 /codeIgniter/application/controllers/Welcome.php

<?php

defined('BASEPATH') OR exit('No direct script access allowed');


class Welcome extends CI_Controller {


/**

@brief 기본 Wellcome to CodeIgniter! 페이지 지정

*/

public function index() {

$this->load->view("welcome_message");

}


/**

* @brief 사이트 헤더, 푸터가 자동으로 추가

*/

public function _remap($method) {


// brief 헤더 load

$this->load->view("layer/headder_view");


if(method_exists($this, $method)) {

$this->{"{$method}"}();

}


// @brief 푸터 load

$this->load->view("layer/footer_view");

}

}




# 헤더 레이아웃

 /codeIgniter/application/views/layer/headder_view.php

<header style="background-color:#333333;padding-top:30px;padding-left:20px;padding-bottom:20px;">

    <a href="http://magic.wickedmiso.com/" style="color:#FFFFFF;text-decoration:none;">

        <span style="font-size:20px;font-weight:bold;color:#C52D2F;">사악미소</span>의 현대마법의 공방

    </a>

</header>




# 푸터 레이아웃

 /codeIgniter/application/views/layer/footer_view.php

<footer style="background-color:#333333;padding-top:15px;padding-left:40px;padding-bottom:15px;color:#FFFFFF;">

    Created by saakmiso

</footer>





# 출력결과








반응형
//

[CodeIgniter] 폼 검증하기[CodeIgniter] 폼 검증하기

Posted at 2019. 12. 17. 18:36 | Posted in PHP/CodeIgniter
반응형




■ 형식 검토



http://www.ciboard.co.kr/user_guide/kr/libraries/form_validation.html


규칙

파라미터

설명

required

NO

 · 검사 대상이 비어있으면 FALSE를 리턴한다.

matches

YES

 · 검사 대상이 파라미터의 값과 일치하지 않을 때 FALSE를 리턴한다.

is_unique

YES

 · 파라미터에서 테이블 및 필드 이름이 유일하지 않다면 FALSE를 리턴한다.

alpha

NO

 · 검사 대상이 알파벳 이외의 문자를 포함할 때 FALSE를 리턴한다.

alpha_numeric

NO

 · 검사 대상이 알파벳이나 숫자가 아닌 문자를 포함할 때 FALSE를 리턴한다.

alpha_dash

NO

 · 검사 대상이 알파벳, 숫자, 밑줄(...), 대시(...) 이외의 문자를 포함할 때 FALSE를 리턴한다.

numeric

NO

 · 검사 대상이 숫자 이외의 문자를 포함할 때 FALSE를 리턴한다.

integer

NO

 · 검사 대상이 정수 이외의 문자를 포함할 때 FALSE를 리턴한다.

decimal

YES

 · 검사 대상이 소수 이외의 문자를 포함할 때 FALSE를 리턴한다.

is_natural

NO

 · 검사 대상이 자연수 이외의 문자를 포함할 때 FALSE를 리턴한다.

   ( 0, 1, 2, 3, ... 등인지 검사 )

is_natural_no_zero

NO

 · 검사 대상이 1 이상의 자연수 이외의 문자를 포함할 때 FALSE를 리턴한다.

   ( 1, 2, 3 ... 등인지 검사 )

valid_email

NO

 · 검사 대상이 유효한 이메일 주소가 아닐 때 FALSE를 리턴한다.

valid_emails

NO

 · 검사 대상이 콤마( , )로 구분된 이메일 주소일 경우에 사용

 · 유효한 이메일 주소가 아닐 때 FALSE를 리턴한다.

   ( 여러개의 이메일을 한꺼번에 검사 )

valid_ip

NO

 · 검사 대상이 유효한 IP 주소가 아닐 때 FALSE를 리턴한다.

 · IP포맷을 검증하기 위해 "ipv4" 또는 "ipv6"를 구별하는 파라미터를 받을 수 있다.



 codeIgniter/system/language/english/form_validation_lang.php

defined('BASEPATH') OR exit('No direct script access allowed');


$lang['form_validation_required'] = "The {field} field is required.";

$lang['form_validation_isset'] = "The {field} field must have a value.";

$lang['form_validation_valid_email'] = "The {field} field must contain a valid email address.";

$lang['form_validation_valid_emails'] = "The {field} field must contain all valid email addresses.";

$lang['form_validation_valid_url'] = "The {field} field must contain a valid URL.";

$lang['form_validation_valid_ip'] = "The {field} field must contain a valid IP.";

$lang['form_validation_valid_base64'] = "The {field} field must contain a valid Base64 string.";

$lang['form_validation_min_length'] = "The {field} field must be at least {param} characters in length.";

$lang['form_validation_max_length'] = "The {field} field cannot exceed {param} characters in length.";

$lang['form_validation_exact_length'] = "The {field} field must be exactly {param} characters in length.";

$lang['form_validation_alpha'] = "The {field} field may only contain alphabetical characters.";

$lang['form_validation_alpha_numeric'] = "The {field} field may only contain alpha-numeric characters.";

$lang['form_validation_alpha_numeric_spaces'] = "The {field} field may only contain alpha-numeric characters and spaces.";

$lang['form_validation_alpha_dash'] = "The {field} field may only contain alpha-numeric characters, underscores, and dashes.";

$lang['form_validation_numeric'] = "The {field} field must contain only numbers.";

$lang['form_validation_is_numeric'] = "The {field} field must contain only numeric characters.";

$lang['form_validation_integer'] = "The {field} field must contain an integer.";

$lang['form_validation_regex_match'] = "The {field} field is not in the correct format.";

$lang['form_validation_matches'] = "The {field} field does not match the {param} field.";

$lang['form_validation_differs'] = "The {field} field must differ from the {param} field.";

$lang['form_validation_is_unique'] = "The {field} field must contain a unique value.";

$lang['form_validation_is_natural'] = "The {field} field must only contain digits.";

$lang['form_validation_is_natural_no_zero'] = "The {field} field must only contain digits and must be greater than zero.";

$lang['form_validation_decimal'] = "The {field} field must contain a decimal number.";

$lang['form_validation_less_than'] = "The {field} field must contain a number less than {param}.";

$lang['form_validation_less_than_equal_to'] = "The {field} field must contain a number less than or equal to {param}.";

$lang['form_validation_greater_than'] = "The {field} field must contain a number greater than {param}.";

$lang['form_validation_greater_than_equal_to'] = "The {field} field must contain a number greater than or equal to {param}.";

$lang['form_validation_error_message_not_set'] = "Unable to access an error message corresponding to your field name {field}.";

$lang['form_validation_in_list'] = "The {field} field must be one of: {param}.";




■ 입력 길이



규칙 

파라미터

설명

min_length

YES

 · 검사 대상의 길이가 파라미터 값보다 작을 때 FALSE를 리턴한다.

max_length

YES

 · 검사 대상의 길이가 파라미터 값보다 클 때 FALSE를 리턴한다.

exact_length

YES

 · 검사 대상의 길이가 파라미터 값과 다를 때 FALSE를 리턴한다.

greater_than

YES

 · 검사 대상이 지정된 값보다 작거나 숫자가 아닌경우 FALSE를 리턴한다.

less_than

YES

 · 검사 대상이 지정된 값보다 크거나 숫자가 아닌 경우 FALSE를 리턴한다.





■ 폼 검증 예


<?php


      // @details 필드의 앞뒤 공백제거 | 필수 필드 | 5자 이상 | 12자 이하 | 필드에서 XSS 공격에 해당하는 내용 제거

      $this->form_validation->set_rules( "username", "Username", "trim | required | min_length[5] | max_length[12] | xss_clean" ); 


      // @details 필드의 앞뒤 공백 제거 | 필수 필드 | passconf 필드와 매칭되는지 체크 | MD5로 변환

      $this->form_validation->set_rules( "password", "Password", "trim | required | matches[passconf] | md5" );


      // @details 필드의 앞뒤 공백 제거 | 필수 필드 | 이메일 형식이 맞는지 체크

      $this->form_validation->set_rules( "email", "Email", "trim | required | valid_email" );


?>











■ 폼 검증 에러메시지를 한글로 표시하기


 codeIgniter/application/config/config.php

<?php

defined('BASEPATH') OR exit('No direct script access allowed');


      // ~~ 이 하 생 략 ~~


/*

|--------------------------------------------------------------------------

| Default Language

|--------------------------------------------------------------------------

|

| This determines which set of language files should be used. Make sure

| there is an available translation if you intend to use something other

| than english.

|

*/

// $config['language'] = "english";

$config['language'] = "korea";


      // ~~ 이 하 생 략 ~~





 codeIgniter/system/language/korean/form_validation_lang.php

defined('BASEPATH') OR exit('No direct script access allowed');


$lang['form_validation_required'] = "{field} 필드가 필요합니다.";

$lang['form_validation_isset'] = "{field} 필드는 반드시 필요한 값입니다.";

$lang['form_validation_valid_email'] = "{field} 필드는 유효한 이메일 주소를 반드시 포함해야 합니다.";

$lang['form_validation_valid_emails'] = "{field} 필드는 모든 유효한 이메일 주소를 반드시 포함해야 합니다.";

$lang['form_validation_valid_url'] = "{field} 필드는 유효한 URL을 포함해야 합니다.";

$lang['form_validation_valid_ip'] = "{field} 필드는 유효한 IP를 포함해야 합니다.";

$lang['form_validation_valid_base64'] = "{field} field must contain a valid Base64 string.";

$lang['form_validation_min_length'] = "{field} 필드의 길이는 최소한 {param} 개의 문자를 넘어야 합니다.";

$lang['form_validation_max_length'] = "{field} 필드의 길이는 최대 {param} 개의 문자를 넘어서는 안됩니다.";

$lang['form_validation_exact_length'] = "{field} 필드의 길이는 정확히 {param} 개의 문자여야 합니다.";

$lang['form_validation_alpha'] = "{field} 필드는 알파벳 문자만 포함할 수 있습니다.";

$lang['form_validation_alpha_numeric'] = "{field} 필드는 알파벳 문자와 숫자만 포함할 수 있습니다.";

$lang['form_validation_alpha_numeric_spaces'] = "{field} 필드는 알파벳 문자와 숫자, 그리고 공백만 포함할 수 있습니다.";

$lang['form_validation_alpha_dash'] = "{field} 필드는 알파벳 문자와 숫자, 밑줄, 대시만 포함할 수 있습니다.";

$lang['form_validation_numeric'] = "{field} 필드는 반드시 숫자만 포함할 수 있습니다.";

$lang['form_validation_is_numeric'] = "{field} 필드는 반드시 숫자만 포함할 수 있습니다.";

$lang['form_validation_integer'] = "{field} 필드는 반드시 정수만 포함할 수 있습니다.";

$lang['form_validation_regex_match'] = "{field} 필드는 형식이 맞지 않습니다.";

$lang['form_validation_matches'] = "{field} 필드가 {param} 필드와 일치하지 않습니다.";

$lang['form_validation_differs'] = '{field} 필드는 {param} 필드와 값이 달라야만 합니다.';

$lang['form_validation_is_unique'] = "{field} 필드는 고유값을 포함해야 합니다.";

$lang['form_validation_is_natural'] = "{field} 필드는 자연수만 포함할 수 있습니다.";

$lang['form_validation_is_natural_no_zero'] = "{field} 필드는 0을 초과하는 자연수만 포함할 수 있습니다.";

$lang['form_validation_decimal'] = "{field} 필드는 10진수여야 합니다.";

$lang['form_validation_less_than'] = "{field} 필드는 {param} 필드보다 작은 값이어야 합니다.";

$lang['form_validation_less_than_equal_to'] = "{field} 필드는 {param} 필드보다 작거나 같은 값이어야 합니다.";

$lang['form_validation_greater_than'] = "{field} 필드는 {param} 필드보다 큰 숫자여야 합니다.";

$lang['form_validation_greater_than_equal_to'] = "{field} 필드는 {param} 필드보다 크거나 같은 숫자여야 합니다.";

$lang['form_validation_error_message_not_set'] = "{field} 필드는 오류 메세지와 일치하여 사용할 수 없습니다.";

$lang['form_validation_in_list'] = "{field} 필드는 다음중 하나여야 합니다. : {param}";







반응형
//

[CodeIgniter] 컨트롤러(Controllers) 사용방법[CodeIgniter] 컨트롤러(Controllers) 사용방법

Posted at 2019. 7. 31. 16:39 | Posted in PHP/CodeIgniter
반응형




참고 : http://www.ciboard.co.kr/user_guide/kr/general/controllers.html





■ 컨트롤러란 무엇인가?



컨트롤러는 URL과 상호작용하는 클래스 파일이라고 할 수 있다.


파일명(File.php)과 클래스(File)명의 첫글자는 항상 대문자 이여야 한다.


클래스명은 컨트롤러 파일명과 동일해야 한다.



 ./application/controllers/Blog.php

<?php

if(!defined("BASEPATH")) { exit("No direct script access allowed"); }


class Blog extends CI_Controller {

public function index() {

echo "사악미소의 현대마법의 IT공방";

}

}


/* END of file Blog.php */

/* Location : ./application/controllers/Blog.php */




# 출력결과 : http://code-igniter.com/index.php/blog/










■ 함수 호출하기




이전 예제에서 호출된 함수는 index( )였는데, index( ) 함수는 URI에서 두번째 새그먼트가 전달되지 않은 경우 기본적으로 실행이 된다.


이번에는 URI에 새그먼트 값을 추가하여 Blog라는 클래스에 comments( )라는 함수를 호출해 보자.


 ./application/controllers/Blog.php

<?php

if(!defined("BASEPATH")) { exit("No direct script access allowed"); }


class Blog extends CI_Controller {

public function index() {

echo "사악미소의 현대마법의 IT공방";

}

public function comments() {

echo "방문해 주셔서 감사합니다";

}

}


/* END of file Blog.php */

/* Location : ./application/controllers/Blog.php */




# 출력결과 : http://code-igniter.com/index.php/blog/comments




그럼 위와 같이 새로운 메세지가 출력되는 것을 확인 할 수 있다.








■ URI 세그먼트 값을 함수에 전달하기




 ./application/controllers/Products.php

<?php

if(!defined("BASEPATH")) { exit("No direct script access allowed"); }


class Products extends CI_Controller {

public function shoes($sandals, $id) {

echo sprintf("sandals : %s", $sandals);

echo "<br/>";

echo sprintf("id : %s", $id);

}

}


/* END of file Products.php */

/* Location : ./application/controllers/Products.php */





# 출력결과 : http://localhost/index.php/products/shoes/sandals/123










■ 기본 컨트롤러 정의



코드이그나이터에서는 새그먼트 없이 사이트의 루트 URI만 요청될때 실행되는 기본 컨트롤러를 지정할 수 있다.


기본 컨트롤러를 지정하려면 ../application/config/routes.php 파일의 $route[ 'default_controller' ] 의 값을 설정해 주면된다.


 ./application/config/routes.php

<?php

if(!defined("BASEPATH")) { exit("No direct script access allowed"); }


      /* 주 석 생 략 */


$route['default_controller'] = "First";

$route['404_override'] = "";

$route['translate_uri_dashes'] = FALSE;



이제 First.php 파일을 controllers 디렉토리에 생성하고.


아래와 같은 코드를 작성해 보자.



 ./application/controllers/Blog.php

<?php

if(!defined("BASEPATH")) { exit("No direct script access allowed"); }


class First extends CI_Controller {

public function index() {

echo "https://www.google.co.kr";

}

}


/* END of file First.php */

/* Location : ./application/controllers/First.php */





# 출력결과 : http://localhost




단순히 http://localhost라는 기본 주소를 입력하는 것만으로도


http://localhost/index.php/first 를 호출한것과 같은 결과를 얻을 수 있다.









■ 함수요청 재맵핑하기




일반적으로 URI의 두번째 새그먼트는 컨트롤러내의 어떤 함수를 실행할 것인가를 결정하낟.


이런 일반루틴을 재정의 하여 원하는 액션으로 바꿀 수 있다.



 http://code-igniter.com/index.php/rmapping/zerg 

<?php

if(!defined("BASEPATH")) { exit("No direct script access allowed"); }


class Rmapping extends CI_Controller {

public function _remap($method) {

if($method === "zerg") {

$this->zerg();

} else if($method === "protoss") {

$this->protoss();

} else {

$this->terran();

}

}

public function zerg() {

echo "군단의 심장";

}

public function protoss() {

echo "공허의 유산";

}

public function terran() {

echo "자유의 날개";

}

}


/* END of file Rmapping.php */

/* Location : ./application/controllers/Rmapping.php */




# 출력결과 : http://localhost/index.php/rmapping/zerg




위와 같이 출력되는 것을 확인 할 수 있다.




※ 참고


../application/config/routes.php 페이지의 


$route['default_controller'] 값을 "Rmapping" 으로 변경하고 사용하게 되면



# 출력결과 : http://localhost/index.php/rmapping/protoss









■ Private 접근제어 함수



PHP에는 public, private, protected 라는 3가지 접근 제어자가 존재한다.


접근제어자

기     능

public

 · class 밖에서도 함수에 접근이 가능하다.

 · 아무것도 명시하지 않으면 기본값이 public으로 선언된다.

private

 · 클래스 내부에서만 접근이 가능하다.

 · 상속이 불가능 하다.

protected

 · 클래스 내부에서만 접근이 가능하다.

 · 상속이 가능하다.







<?php

if(!defined("BASEPATH")) { exit("No direct script access allowed"); }


class Access extends CI_Controller {

public function index() {

echo "접 근 가 능";

}

private function _utility() {

echo "접 근 불 가";

}

}


/* END of file Access.php */

/* Location : ./application/controllers/Access.php */




# 출력결과 : http://localhost/index.php/Access/index




# 출력결과 : http://localhost/index.php/Access/_utility



위와같이 URI의 새그먼트 값으로 _utility 함수를 호출하려고 하는경우


페이지를 찾을 수 없다는 404 Page Not Found


에러가 발생하는것을 확인 할 수 있다.








■ 클래스 생성자




컨트롤러에서 생성자를 사용하고자 한다면 생성자아래 반드시 아래의 코드가 들어있어야 한다.


 parent :: __construct( );


그렇지 않으면 직접 구현한 모든 생성자가 부모 controoler의 생성자를 재정의 하기 때문에


반드시 부모 controller를 수동으로 호출해 주어야 한다.



생성자는 클래스가 초기화될 때 어떤 기본값들을 설정해야 한다거나 어떤 프로세스를 수행해야 할때 유용하다.


생성자는 리턴값이 있어서는 안된다.



 

<?php

if(!defined("BASEPATH")) { exit("No direct script access allowed"); }


class Products extends CI_Controller {

public function __construct() {

parent::__construct();

}

}


/* END of file Products.php */

/* Location : ./application/controllers/Products.php */










반응형
//