ajaxlink显示空白#Yii

时间:2014-04-18 13:14:59

标签: yii

我的ajaxlink显示#而不是链接。我尝试使用chtml::link,并且显示正确。

 <?php 
    echo CHtml::ajaxLink("<img alt=".$data->text."
    src=".Yii::app()->assetManager->publish(Yii::app()->basePath."/images/".$data->img)." 
        title=".$data->text." height=100px width=100px/>",
    Yii::app()->createUrl('controller/action',array('id'=>$data->id)),
    array(
        "type" => "post",
        "data" => "js:{ids:$.fn.yiiGridView.getSelection('chck-id')}",
         "update" => "#grid"));
 ?>

2 个答案:

答案 0 :(得分:0)

查看ajaxLink函数

public static function ajaxLink($text,$url,$ajaxOptions=array(),$htmlOptions=array())
{
    if(!isset($htmlOptions['href']))
        $htmlOptions['href']='#';
    $ajaxOptions['url']=$url;
    $htmlOptions['ajax']=$ajaxOptions;
    self::clientChange('click',$htmlOptions);
    return self::tag('a',$htmlOptions,$text);
}

如您所见,href来自htmlOptions。正确的代码是:

CHtml::ajaxLink("<img alt='".$data->text."'
src='".Yii::app()->assetManager->publish(Yii::app()->basePath."/images/".$data->img)."' 
    title='".$data->text."' height=100px width=100px/>",
'',
array(
    "type" => "post",
    "data" => "js:{ids:$.fn.yiiGridView.getSelection('chck-id')}",
     "update" => "#grid"
),array(
    'href'=>Yii::app()->createUrl('controller/action',array('id'=>$data->id))
));

答案 1 :(得分:0)

希望你的其他方法有效!但您可以尝试重复此urlhref的链接。

echo CHtml::ajaxLink("<img alt='" . $data->text . "'
  src='" . Yii::app()->assetManager->publish(Yii::app()->basePath . "/images/" . $data->img) . "' 
  title='" . $data->text . "' height=100px width=100px/>", 
  Yii::app()->createUrl('controller/action', array('id' => $data->id)),
  array(
    "type" => "post",
    "data" => "js:{ids:$.fn.yiiGridView.getSelection('chck-id')}",
    "update" => "#grid"
  ), array(
    'href' => Yii::app()->createUrl('controller/action', array('id' => $data->id))
  )
);