我有一个 User 模型和一个 Notes 模型。
用户模型:
class User extends AppModel {
var $name = 'User';
var $hasMany = array(
'Note'
);
}
用户控制器:
public function notesview()
{
$allnotes = $this->User->Note->find('all', array('order'=>'Note.created DESC'));
}
查看元素:
$allnotes = $this->requestAction(array('controller'=>'Users', 'action'=>'notesview'));
foreach($allnotes as $viewnotes):
{
echo $viewnotes['Note']['notes'];
echo "<br>";
echo $viewnotes['Note']['created'];
echo "<br>";
echo $viewnotes['User']['name'];
}
endforeach;
现在在元素中您可以看到“ echo $viewnotes['User']['name']; ”。我希望在此元素中检索 User 模型中的 Name 字段,但出现以下错误:
Notice (8): Undefined index: User [APP\View\Elements\notes.ctp, line 39]