当用户登录时,我需要更改主题
在Application。php
在AppController。php
public function bootstrap(): void
{
$this->addPlugin('BootstrapUI');
// Call parent to load bootstrap from files.
parent::bootstrap();
$this->addPlugin('CakeDC/Users', ['routes' => true, 'bootstrap' => true]);
//$this->addPlugin(\CakeDC\Users\Plugin::class);
Configure::write('Users.config', ['users']);
}
这个错误
public function beforeFilter(EventInterface $event)
{
parent::beforeFilter($event);
$user = $this->Authentication->identify();
if ($user) {
$this->viewBuilder()->setlayout( 'CakeLte.default' );
}
}
###假设你已经在你的应用程序中正确配置了认证组件,你可以像下面这样检查用户是否连接:
以防万一,这是对您有用的代码示例。
if($this->Authentication->getIdentity()) {
// user logged
} else {
// user not logged
}
在你的控制器中:
在你看来:
$this->Authentication->getIdentity();
// Access to a field
$this->Authentication->getIdentity()->username;
// Access to a method of the entity
$this->Authentication->getIdentity()->isAdmin();
我承认这是很难找到它的文档看起来像是放弃了一些特性。
$this->request->getAttribute('identity')
// Access to a field
$this->request->getAttribute('identity')->username;
// Access to a method of the entity
$this->request->getAttribute('identity')->getOriginalData()->isAdmin();