2013-03-28 3 views
0

나는 code-igniter로 작업 중이며 cron 작업에서 함수를 실행 중이다.cron 명령에서 codeigniter 함수로 매개 변수를 전달하는 방법은 무엇입니까?

class event extends CI_Controller { 
    public function newEvent() 
    { 
     //some process here using the parameter 
    } 

} 

cron 명령 :

* */2 * * * /usr/bin/php /var/www/project/index.php 'event/newEvent/parameter' 

내가 크론 명령 작성과 같은 매개 변수를 전달하고 newEvent 기능에 해당 매개 변수와 함께 몇 가지 과정을 수행합니다.

cron 명령에서 매개 변수를 받기 위해 필자가 작성해야하는 추가 코드.

감사합니다.

답변

1

에 명령 줄에서 명령을 실행하는 방법을

* */2 * * * /usr/bin/php /var/www/project/index.php event newEvent parameter 
+0

그건 또 다른 좋은 방법입니다. 그것은 상자 밖으로 일 했는가 또는 당신은 당신의 방법에 매개 변수를 추가해야 했는가? –

+0

내 메서드에 매개 변수를 추가했습니다. – ehp

1

매개 변수를 함수에 추가하기 만하면됩니다.

class event extends CI_Controller { 

    public function newEvent($parameter) 
    { 
     //some process here using the parameter 
     echo $parameter; 
    } 

} 

기본 라우팅 엔진은 매개 변수를 처리하여 사용자의 기능에 전달합니다. 이 매개 변수가 선택 사항이라면 기본값으로 초기화하십시오.

public function newEvent($parameter = 'default') 
    { 
     //some process here using the parameter 
     echo $parameter; 
    } 

편집 :의 @의 dm03514 응답을 읽은 후, documentation recommends 공백 대신 슬래시 사용하여 응용 프로그램을 호출 할 것으로 보인다.

cron 명령은 내가 이것을 시도하고 나를 위해 일하고 자신의 문서

php index.php event newEvent parameter

2

CI explains해야한다.

* */2 * * * /usr/bin/curl http://domain.com/index.php/event/newEvent/parameter 
+0

당신은 저보다 더 빠릅니다! :) –

관련 문제