0

我有 2 个视图,postview.ctpusercomment.ctp,调用相同的comment.ctp元素。此元素使用 UploadPack 帮助程序显示图像。但是usercomment.ctp上的图像没有显示并且有这个错误信息

Notice (8): Undefined index: User [APP\Plugin\upload_pack\Model\Behavior\UploadBehavior.php, line 222] 

line 222: $settings = self::$__settings[$modelName][$field];

usercomment.ctp中的 self::$__settings为空,但在postview.ctp中它不是空的并且图像正确显示。

评论.ctp:

<?php echo $this->Html->link($this->upload->image(
    $comment['User'], 
    'User.avatar',
    array('style' => 'thumb'),  
    array('class' => array('img-responsive', 'img-rounded'))
), 
array('controller' => 'users', 
      'action' => 'view', 
      $comment['User']['id']),
      array('escape' => false) 
) ?>

这是从两个视图调用 comment.ctp 的代码。

<?php if (!empty($comments)): ?>
    <?php foreach ($comments as $comment): ?> 
        <?php echo $this->element('comment',array('comment' => $comment));?>
    <?php endforeach; ?>
<?php endif; ?>

我检查了 $comment 数组,它们是相同的。如何解决?

4

1 回答 1

0

在评论控制器中的用户评论操作上加载用户模型。

public function usercomments($id) {
    $this->loadModel('User');
    if($this->Auth->loggedIn()){
    .....
于 2013-09-25T13:49:49.470 回答