zcyxm 2012-05-19 17:49:37 4128次浏览 6条回复 0 0 0

view里面的代码

<?php echo CHtml::ajaxLink(CHtml::encode('('.$data->good.')有意思'),array('site/zcyxm','id'=>'1','story_id'=>$data->story_id ),array('replace'=>'#good'.$data->story_id),array('id'=>'good'.$data->story_id));?> |<?php echo CHtml::ajaxLink(CHtml::encode('无聊('.$data->bad.')'),array('site/zcyxm','id'=>'2','story_id'=>$data->story_id ),array('replace'=>'#bad'.$data->story_id),array('id'=>'bad'.$data->story_id));?> [/code]对应的控制器[code]public function actionZcyxm(){
		$sid = $_GET['story_id'];
		$id = $_GET['id'];
		$ids = array('1','2');
		$id = in_array($id,$ids)?$id:'1';
		
		if ($id == '1'){
			$model = Stories::model()->updateCounters(array('good'=>1),array('condition'=>'story_id='.$sid));
			if ($model){
				$good=Stories::model()->findByPk($sid);
				//echo $good->good;
				echo CHtml::encode('('.$good->good.')有意思');
			}
		}else {
			$model = Stories::model()->updateCounters(array('bad'=>1),array('condition'=>'story_id='.$sid));
			if ($model){
				$good=Stories::model()->findByPk($sid);
				//echo $good->bad;
				echo CHtml::encode('无聊('.$good->bad.')');
			}
		}
		
}

最后生成的效果图: [attach]729[/attach]

现在问题出现了,第一页里面可以点,就是点有意思或者无聊,会成功,点完后,相对应的有意思或者无聊会增加1,然后变成灰色,刷新后继续能点。但是第二页以及以后的就没反应了。

求大神帮忙看看…

周六人有点少唔…期待大神的回答

  • 回复于 2012-05-19 17:54 举报

    另外,我想用日历弄一个Archive,求给点建议。怎样给传值…文档看不太明白额。

    [attach]730[/attach]

  • 回复于 2012-05-19 18:30 举报

    貌似发现了出问题的地方了,但是不知道该怎么解决.

    翻页后,相对应的story_id没有变化…

  • 回复于 2012-05-20 21:32 举报

    顶起~~明天上班了,就有人看了。

  • 回复于 2012-05-21 11:08 举报

    还没有人帮我么.....:'(

    求大大帮忙啊。舰长大人,你在哪,俺需要你!

    我的办法是,在ajaxLink里面加

    <?php echo CHtml::ajaxLink(CHtml::encode('('.$data->good.')有意思'),array('site/zcyxm','id'=>'1','story_id'=>$data->story_id ),array('replace'=>'#good'.$data->story_id),array('id'=>'good'.$data->story_id,'href'=>Yii::app()->getRequest()->getUrl().'#'));?> |<?php echo CHtml::ajaxLink(CHtml::encode('无聊('.$data->bad.')'),array('site/zcyxm','id'=>'2','story_id'=>$data->story_id ),array('replace'=>'#bad'.$data->story_id),array('id'=>'bad'.$data->story_id,'href'=>Yii::app()->getRequest()->getUrl().'#'));?> 
    

    也就是在第四个参数里面加了 'href'=>Yii::app()->getRequest()->getUrl().'#'

    但是这样的话,再次翻页的时候,依然会出现问题。。。

  • 回复于 2012-05-21 17:39 举报

    结贴拉倒...不纠结了。

    用了个最傻瓜的办法,翻页不用ajax翻页。囧;P

您需要登录后才可以回复。登录 | 立即注册