Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用模式窗口将记录添加到当前页面,并在Yii中通过ajax进行更新,_Php_Jquery_Yii_Modal Dialog - Fatal编程技术网

Php 使用模式窗口将记录添加到当前页面,并在Yii中通过ajax进行更新,

Php 使用模式窗口将记录添加到当前页面,并在Yii中通过ajax进行更新,,php,jquery,yii,modal-dialog,Php,Jquery,Yii,Modal Dialog,我有一个有帖子和评论的页面。我有一个评论按钮,可以打开一个模式窗口并允许发表评论。我可以得到的意见,以节省没有问题。我可以让页面更新或模式关闭,但我不能让两者同时发生。我花了4个小时来处理我能找到的每一个例子。谢谢你的帮助 这是我的控制器 public function actionIndex(){ $this->layout='account2'; $feedItems=NewsfeedItem::model()->getFeed('accoun

我有一个有帖子和评论的页面。我有一个评论按钮,可以打开一个模式窗口并允许发表评论。我可以得到的意见,以节省没有问题。我可以让页面更新或模式关闭,但我不能让两者同时发生。我花了4个小时来处理我能找到的每一个例子。谢谢你的帮助

这是我的控制器

public function actionIndex(){  
        $this->layout='account2';
        $feedItems=NewsfeedItem::model()->getFeed('account');
        $player=Players::model()->findByPK(Yii::app()->user->id);
        $this->render('index', array('player'=>$player, 'feedItems'=>$feedItems));
    }

public function actionAddcomment(){
    $comment=new NewsfeedComment;
    $comment->text=$_POST['comment'];
    $comment->players_id=Yii::app()->user->id;
    $comment->newsfeed_item_id=$_POST['newsfeeditem'];
    $comment->datetime=date('Y-m-d h:i:s');
    $comment->save();
    $feedItems=NewsfeedItem::model()->getFeed('account');              
    $this->renderPartial('_newsfeed', array('feedItems'=>$feedItems), false, true);     
}
这些是我的视图文件

索引

欢迎您,


_新闻提要

<?php 
foreach($feedItems as $item){
    $onclick='$(mydialog' . $item->id . ').dialog("open"); return false;';
    echo "<h6>" . $item->getAuthor() . "</h6><br />";
    echo '"' . $item->text . '" - ';
    echo CHtml::link('Comment', '#', array(
       'onclick'=>$onclick,
    ));
    echo '<br />';
    $comments=array_slice($item->comments, -5);
    foreach($comments as $comment){

        echo '<h6>';
        echo $comment->text;
        echo '</h6><br />';
    }
    $this->beginWidget('zii.widgets.jui.CJuiDialog',array(
        'id'=>"mydialog" . $item->id,
        // additional javascript options for the dialog plugin
        'options'=>array(
            'title'=>'Comment',
            'autoOpen'=>false,
        ),
    ));

        ?>
        <form method='POST' action='/account/addcomment'>
            <textarea name='comment'></textarea>
            <input type='hidden' name='newsfeeditem' value='<?php echo $item->id; ?>'>
            <?php $closeclick='js:function(){$(mydialog' . $item->id . ').dialog("close");}'; ?>
            <div class="row buttons">
                <?php echo CHtml::ajaxSubmitButton('Add Comment', '/account/addcomment', array(
                    'update'='#newsfeed', //REMOVING THIS LINE ALLOWS MODAL TO CLOSE
                    'success'=>'js:'
                        .'function(){'
                          .'$("#mydialog' . $item->id . '").dialog("close");'
                        .'}',
                )); ?>
            </div>
        </form>

    <?php
    $this->endWidget('zii.widgets.jui.CJuiDialog');


    echo "<br />";
}
?>

在渲染部分中定义另外两个参数:

$this->renderPartial('_newsfeed', array('feedItems'=>$feedItems),false,true);

这似乎并没有解决问题。正如现在的代码所示,如果我发表评论,模态将关闭,但不会更新页面。
$this->renderPartial('_newsfeed', array('feedItems'=>$feedItems),false,true);