[英]How to make cakedc Users available in the whole application in cakephp
How do i make the cakedc users plugin available in all my application. 我如何在我的所有应用程序中使用cakedc users插件。 i tried using some of the variables in the default.ctp layout and i get "undefined index" error message even after loading the user model in the appController.php file.
我尝试在default.ctp布局中使用某些变量,即使在将用户模型加载到appController.php文件中后,也收到“未定义索引”错误消息。 please how do i make the plugin available through out the application.
请如何在整个应用程序中使插件可用。 here is what i have tried (AppController.php):
这是我尝试过的(AppController.php):
class AppController extends Controller {
public function beforeFilter(){
return $this->set('user', $this->getuser());
}
function getuser(){
if($this->Session->read('Auth.User.id')){
$this->loadModel('User');
$user = $this->User->find('first',array(
'conditions'=>array('User.id'=>$this->Session->read('Auth.User.id')),'fields'=>array('id'))
);
if (!$user || empty($user)) return false;
return $user;
}
return false;
}
}
and how do i output it in the view, that is default.ctp? 以及如何在视图中将其输出为default.ctp?
When you use loadModel()
you need to include the plugin name using Cake's plugin syntax ( ie pluginName.modelName
):- 当使用
loadModel()
,需要使用Cake的插件语法( 即 pluginName.modelName
)包括插件名称:-
$this->loadModel('Users.User');
Otherwise it will look for the User model in your app not the plugin. 否则,它将在您的应用程序而不是插件中查找用户模型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.