2014-03-29 76 views
-1

我使用Yii框架,但如果我沒有錯,我認爲這是對myjquery非法串偏移「名稱」

我呈現的帖子

<?php 
/* @var $this PostController */ 
/* @var $data Post */ 
?> 

-- Get Post Subject 

    <b> <?php echo CHtml::encode(Contest::model()->getAttributeLabel('subject')); ?>:</b> 
    <?= CHtml::encode($data['subject']); ?> 

-- Place to get the controller/action from js script 

    <div id="dataComment<?php echo $data['id']; ?>" data-url="<?php echo Yii::app()->createUrl('post/ajax', array('post_id' => $data['id'])); ?>"></div> 

-- Button Link -- error when I click on the following button 

**-- localhost/blog/index.php/post/ajax?post_id=16 -- Illegal string offset 'name'** 


    <p><input type ="button" id="comment<?php echo $data['id']; ?>" 
    value="<?php echo ($comment_exist == NULL) ? 'Comment' : 'Cancel my Comment'; ?>"></p> 

列表相關 - jQuery腳本 --on文件準備

$('[id^="comment"]').click(function(e) { 

      var $thisClicked = $(this); 
      var parameter = $thisClicked.attr('id'); 
      parameter = parameter.replace('comment',''); 

      $.ajax({ 
       'url' : $('#dataComment' + parameter).data('url'), 
       'type' : 'POST', 
       'update': '.form', 
      });      

      $thisClicked.parent().next('.form').fadeIn(1500).slideDown(1300); 

     }); 

- 中郵控制器阿賈克斯行動

public function actionAjax($post_id){ 

    $model = new Comment; 

    $this->renderPartial('_formComment',array(
      'model'=>$model, 
      'post_id'=>$post_id, 

     )); 
} 

- _formComment.php

<div class="form" style="display:none"> 

     <?php $form=$this->beginWidget('CActiveForm', array( 
      'id'=>'comment-form', 
      'enableAjaxValidation'=>true, 
      'enableClientValidation'=>true, 
      'focus'=>array($model,'comment'),    
      )); 
     ?> 

     <div class="row"> 
      <?php echo $form->labelEx($model,'comment'); ?> 
      <?php echo $form->textField($model,'comment',array('size'=>60,'maxlength'=>140)); ?> 
      <?php echo $form->error($model,'comment'); ?> 
     </div> 

     <?php echo $form->hiddenField($model,'post_id',$post_id); ?> 


     <div class="row buttons"> 

      <?php 
        echo CHtml::ajaxButton('ajaxButton', 

        array(
        'type' => 'POST', 
        'success'=>'js:function(string){ alert(string); }'), 
        array('class'=>'someCssClass',)); 

        ?> 


      <p><input type ="button" id = "cancelComment" value="Cancel"></p> 
      <p><input type ="button" id = "deleteComment" value="Delete"></p> 
     </div> 

     <?php $this->endWidget(); ?> 
    </div> 

預先感謝您的幫助

+0

$就沒有按」沒有「更新」設置:http://api.jquery.com/jQuery.ajax/ –

+0

可能的重複[非法字符串偏移警告PHP](http://stackoverflow.com/questions/9869150/illegal-string-offset-warning-php) – CBroe

回答

0

更換你的隱藏字段

<?php echo $form->hiddenField($model,'post_id',$post_id); ?> 

<?php $form->hiddenField($model,'post_id',$post_id); ?> 
+0

偉大的,它的工作原理! – trinocle