CI 묻고 답하기

제목 rest api 적용 후 경로문제
카테고리 CI 4 관련
글쓴이 통달 작성시각 2020/06/25 14:33:10
댓글 : 3 추천 : 0 스크랩 : 0 조회수 : 9944   RSS

rest api를 적용한 후에 사용을 하고 잇습니다.

사용중 용도별로 정리를 하고 싶은데...

현재는 controllers 안에 LoginApi.php , ProductApi.php 등 용도별로 php파일을 만들어서 정리를 했는데요

이걸 폴더를 만들어서 그 안에 정리를 해 두고 싶으서 폴더를 만들었습니다

controllers > member > LoginApi.php 이런식으로 만들었는데 이렇게 만들고 난 다음부터는 404 not found 가 계속 뜹니다.

그래서 구글링 중에 하나 찾은게..

controllers > > api > member > LoginApi.php 이런식으로 api폴더를 하나 만들고 그 안에 다시 폴더별로 정리를 했습니다.

이때부터는 404 not found 가 안뜨고 계속 에러가 납니다.

에러내용은

Status codes must be numeric

 

 

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Api::$http_status

Filename: libraries/RestController.php

Line Number: 547

Backtrace:

File: /home/app/html/application/libraries/RestController.phpLine: 547Function: _error_handler

File: /home/app/html/index.phpLine: 315Function: require_once

 

 

A PHP Error was encountered

Severity: Notice

Message: Use of undefined constant HTTP_OK - assumed 'HTTP_OK'

Filename: libraries/RestController.php

Line Number: 664

Backtrace:

File: /home/app/html/application/libraries/RestController.phpLine: 664Function: _error_handler

File: /home/app/html/application/libraries/RestController.phpLine: 547Function: response

File: /home/app/html/index.phpLine: 315Function: require_once

 

위와 같은 에러가 납니다.

 

다시 위 문제에 대해 구글 하다가 찾지 못하고 질문 남깁니다.

 

아무레도 경로문제인거 같은데요....

 

일단 제가 원하는 거는 controller 폴더 안에 기능별로 api를 정리하고 싶은데 현재 restapi는 controller 폴더 다음에 바로 작성을 해야

작동이 되는거 같습니다.

 

이걸 해결할 방법이 없을까요?

 

미리 감사드립니다~~~~~

 다음글 CLI 상에서 실행시 오류 (1)
 이전글 모델 500 에러에 대해 (4)

댓글

한대승(불의회상) / 2020/06/25 15:04:41 / 추천 0

소스 코드가 없어 정확히 알수 없지만 namespace 오류 같습니다.

폴더를 만들어 주셨다면 namespace에 폴더명도 넣어서 수정해 주셔야합니다.

통달 / 2020/06/25 15:16:43 / 추천 0

 

감사합니다 ㅠㅠ
어디쪽 소스가 필요하신가요?
api파일의 소스는 아래와 같습니다.
로그인 체크 파일입니다.
 
use chriskacerguis\RestServer\RestController;
 
defined('BASEPATH') OR exit('No direct script access allowed');
 
require APPPATH . 'libraries/RestController.php'; 
require APPPATH . 'libraries/Format.php';
 
class MemberLogin extends RestController {
 
    function __construct()
    {
        // Construct the parent class
        parent::__construct();
$this->load->model('member_login');
    }
 
    function index_get()
    {
/*
        if(!$this->get('id'))
        {
            $this->response(NULL, 400);
        }
 
        $user = $this->member_login->get( $this->get('id') );
         
        if($user)
        {
            $this->response($user, 200); // 200 being the HTTP response code
        }
 
        else
        {
            $this->response(NULL, 404);
        }
*/
    }
 
function index_post()
    {
 
        $result = $this->member_login->read( $this->post('userId'), array(
            'userPwd' => $this->post('userPwd'),
            'email' => $this->post('email')
        ));
 
        if($result === null)
        {
            $this->response(array('resultCode' => 1010, 'resultMsg' => 'no match userId, userPwd...'),200);
        }
         
        else
        {
            $this->response(array('resultCode' => 1000, 'resultMsg' => 'Success', 'result' =>array( 'loginInfo' => $result) ) ,200);
        }
         
    }
     
}
 
이렇게 불러와서 사용을 하는데요..

어디에 폴더명을 넣어줘야 하나요?

restapi는 처음 적용해 봐서 ㅠㅠ 코드이그나이트는 3,0버전입니다.

통달 / 2020/06/25 20:18:41 / 추천 0

제 실수로 안되는거옜네요..

그냥 폴더 만들고 폴더별로 저장해도 다 잘 되네요 ^^