soyacode
soyacode

Reputation: 165

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. 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. please how do i make the plugin available through out the application. here is what i have tried (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?

Upvotes: 1

Views: 291

Answers (1)

drmonkeyninja
drmonkeyninja

Reputation: 8540

When you use loadModel() you need to include the plugin name using Cake's plugin syntax (i.e. pluginName.modelName):-

$this->loadModel('Users.User');

Otherwise it will look for the User model in your app not the plugin.

Upvotes: 1

Related Questions