我正在尝试使用
访问另一个组件中的AuthComponentApp::uses('AuthComponent', 'Controller/Component');
class AccessComponent extends Object {
public function foo() {
$this->user = $this->Auth->User();
}
但是检索错误:
未定义属性:AccessComponent :: $ Auth [APP \ Controller \ Component \ AccessComponent.php,第21行]
答案 0 :(得分:4)
您可以将user
用作AuthComponent
App::uses('AuthComponent', 'Controller/Component');
$this->user = AuthComponent::user();
OR包含$components
中的组件:
class AccessComponent extends Component {
public $components = array('Auth');
public function foo() {
$this->user = $this->Auth->user();
}
}
答案 1 :(得分:0)
您可以使用方法访问您的用户
AuthComponent
App::uses('AuthComponent', 'Controller/Component');
$this->user = AuthComponent::user();
CakeSession
App::uses('CakeSession', 'Model/Datasource');
$this->user = CakeSession::read("Auth.User");