脚本宝典收集整理的这篇文章主要介绍了CakePHP 3.x – View中的AuthComponent :: user(),脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
Authcomponent::user()
在View中从Auth组件获取数据.在CakePHP 3.0beta3中,它抛出:
"Error: Class 'AuthComponent' not found"
在AppController中:
public function beforeRender(Event $event) { .... $this->set('Auth',$this->Auth); }
在.ctp模板中:
<?PHP if (!$Auth->user()) { ?> <a class="login" href="<?PHP echo $this->Url->build($Auth->getConfig('LOGinAction')); ?>">Login</a> <?PHP } else { ?> <div class="name"><?PHP echo h($Auth->user('name')); ?></div> <?PHP } ?>
以上是脚本宝典为你收集整理的CakePHP 3.x – View中的AuthComponent :: user()全部内容,希望文章能够帮你解决CakePHP 3.x – View中的AuthComponent :: user()所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。