2010-08-07 3 views
1

"치명적인 오류 : 정의되지 않은 함수 getSContent()를 호출합니다."포함 된 코드로 ... 볼 수 있듯이 : 내 함수가 바로 있습니다!"누락 된 기능"오류가 발생하는 이유는 무엇입니까? 내 기능이 바로 거기에있다!

도와주세요. 나는 잠이 필요하다고 확신한다.

class InfoController extends AppController { 

    var $name = 'Info'; 
    var $helpers = array('Html', 'Session'); 
    var $uses = array(); 

    function display() { 
     $path = func_get_args(); 

     $section = $path[0]; 
     $mainMenuActiveElement = $section; 
     $sectionContent = getSContent($section); 

     $this->set(compact('section', 'mainMenuActiveElement', 'sectionContent')); 
     $this->render('/pages/info'); 
    } 

    function getSContent($section) { 
     $sectionContent = ''; 
     switch ($section) { 
      case 'bases': 
       $sectionContent = 'some content'; 
       break; 
      case 'informacion': 
       $sectionContent = 'some other content'; 
       break; 
     } 
     return $sectionContent; 
    } 

} 

답변

7

컨텍스트를 지정해야합니다. 예를 들어 PHP와는 다른 PHP C++에서는 this을 암시 적으로 가정하지 않습니다.

$sectionContent = $this->getSContent($section); 
+0

오! 나는 정말로 가서 잠을 자야 해. 고맙다 @ VolkerK! – vmarquez

+0

그리고 "암묵적으로 ..."라고 생각하지 않아서 유감입니다. http://en.wikipedia.org/wiki/Name_resolution – VolkerK

+0

PHP에서는 의미가 없습니다. http://stackoverflow.com/questions/3345408/what-is-the-point-of-having-this-and-self-in-php/3376490#3376490 – Artefacto

2

귀하의 기능은 특히 방법입니다. 메서드 이름은 PHP의 함수 테이블에 저장되지 않으며 특정 클래스와 연관됩니다.

당신은 $object는 현재와 같은 인스턴스의 인스턴스 메소드를 호출하기 위해 때 메서드 내 $this을 할 수있는 표기법 $object->methodName(), 그들을 호출해야합니다.

메서드가 정적으로 선언 될 때 표기법은 ClassName::methodName()이됩니다. 특수한 상황에서이 구문을 사용하여 인스턴스 메서드 호출을 호출 할 수도 있습니다.

관련 문제