CakePHP-2.0 How can i get the username from $allposts=$this->paginate('Post'); where user_id is foreign key of posts table?
问题 I'm using CakeDC-Users plugin. <?php class Post extends AppModel { public $useTable='posts'; public $belongsTo = array('User'); public $hasMany=array('Comment'); } I had to use paginate: $allposts=$this->paginate('Post'); I can get the user_id in this way: foreach ($allposts as $post) { debug($post['Post']['user_id']); But i need the username not the user_id. How can i get username? 回答1: The containble feature of CakPHP hides all associated models by default: http://book.cakephp.org/2.0/en