약간 OOP 개념과 혼동 스럽습니다. 나는 아래 varable에 대한 값을 설정하려고합니다.사례 방법을 사용하여 PHP OOP
예 :
나는이 값을 설정하는 세터와 게터를 사용하려면protected $isAdmin;
; caseMethod를 사용하여 setter에 대한 값을 설정하십시오.
아래에 나와있는 것이 더 쉽습니다. 나는 $this->getIsAdmin()
라고하면
protected $isAdmin = null;
public function isAdminWorker()
{
//this will get the preset values for the user; i.e admin worker or visitor.
$theRole = $this->zfcUserAuthentication()->getAuthService()->getIdentity()->getRole();
switch($theRole)
{
case 'admin':
$this->setIsAdmin($theRole);
break;
case 'visitor':
$this->setVisitor($theRole);
break;
}
}
public function setIsAdmin($isAdmin)
{
$this->isAdmin = $isAdmin;
}
public function getIsAdmin()
{
return $this->isAdmin;
}
는 항상 NULL
값을 반환했습니다. 따라서 Case 메서드는 기본적으로 올바른 값을 설정하지 않습니다.
나는 getter와 setter 메서드를 사용하여 값을 설정하는 것에 대해 혼란스러워하고 내가 잘못한 부분에 대한 조언을 제시합니다.
OK 어떤 역할을 "설정"할 필요를 제공하기 때문에 방법은 아마 올바른 값을 설정하지 않습니다. 앞뒤에'$ this-> isAdmin'의 값이 무엇인지보십시오. '$ theRole'의 값을 확인하십시오. 이것은 기본적인 디버깅입니다, 나는 당신이 여기에 어떤 종류의 도움을 줄지 확신하지 못합니다. – Jon
이미 말했듯이'$ theRole'의 값을 확인하십시오. 아마'$ this-> zfcUserAuthentication() -> getAuthService() -> getIdentity() -> getRole()'메소드가 "admin"이나 "visitor"를 반환하지 않을 수도 있습니다. – kinkee
안녕 존과 키키. 모든 기본적인 디버깅 작업을 수행했습니다. 설정되기 전의 값은 null이었고 설정 후의 값은 null이었습니다. 나는 정말로 이것에 대해 조금은 미안하다. 근본적으로. 내 setter 및 getter 메서드가 올바르지 않은 것처럼 보입니다. – andreea115