방금 yii로 로그인했습니다. 내 로그인 테이블 theres "usertype"coloumn 너무 잘 작동하는지 여부를 코드 안에 파일 작성자를 넣어 있지만 그 코드를 실행할 때마다 (심지어 사용자 문자열에 대한 잊지 사용자 형식에 대해 잊지) 확인하십시오. 빈. 다음은 이러한 종류의 문제 때문에 둘 이유가 발생Yii 로그인 사용자 유형이 쓰기가되지 않습니다
0
A
답변
0
코드
구성 요소/useridentity
<?php
class UserIdentity extends CUserIdentity
{
private $_id;
public function authenticate()
{
$user = Trackaccountusers::model()->findByAttributes(array('username'=>$this->username));
if ($user===null) { // No user found!
$this->errorCode=self::ERROR_USERNAME_INVALID;
} else if ($user->password !== ($this->password)) { // Invalid password!
$this->errorCode=self::ERROR_PASSWORD_INVALID;
} else { // Okay!
$this->errorCode=self::ERROR_NONE;
// Store the role in a session:
$this->setState('usertype', $user->usertype);
$file = "log.txt";
$write = ("time_s ".$user->usertype."\n");//
file_put_contents($file, $write, FILE_APPEND);
//$this->_id = $user->id;
}
return !$this->errorCode;
}
public function getId()
{
return $this->_id;
}
}입니다.
- 구성 요소 디렉토리에 대한 쓰기 권한이 있는지 확인하십시오.
chmod -R +x components
구성 요소 디렉토리에 apache/ngnix 사용자 소유자가 있는지 확인하십시오. 당신은
$usertype = isset(Yii::app()->user->usertype) ? Yii::app()->user->usertype : '';
참고 YII 주 (유저 유형) 설정되어 있는지 확인하기 위해 귀하의 의견/컨트롤러에 코드 아래 chown -R www:data:www:data components
사용을 사용하여 설정하거나 할 수 없습니다 당신은하지 않습니다 Yii 사용자 상태를 확인하기 위해 파일을 작성해야합니다. 파일을 쓰는 대신 error_log("usertype = $usertype")
을 사용하거나보기에서 상태를 인쇄하십시오.
구성 요소 디렉토리에 파일을 만들 수있는 충분한 권한이 있습니까? –
file_put_contents를 신뢰할 수 없으므로 파일 시스템 (linux/windows/other)을 신뢰할 수 없습니다. 가장 좋은 방법은 여전히 + 플래그로 fopen을 사용하고 잠겨 있는지 확인하여 다른 프로세스가 사용할 수 없도록하는 것입니다 (Windows에서 파일 어딘가 어딘가에 열고 php가 그냥 실패합니다 file_put_contents 시도 # – DarkMukke