我是yii世界的新手
所以我有一个页面'resultat'并且在选择不同的菜单时,内容需要通过ajax进行更改。
这里的观点:
<!--Content_Resultat-->
<div class="content_resultat">
<div class="header">
<div class="header_top">
<div class="centerheader">
<a href="#">retournez à l'étape en cours</a>
</div>
</div>
<div class="header_bottom">
<ul class="centerlist">
<li><a href="#"><span>1</span> votre piece</a></li>
<li><a href="#"><span>2</span> votre exigence</a></li>
<li><a href="#"><span>3</span> vos autre apareils</a></li>
<li><a href="#"><span>4</span> votre utilisation</a></li>
</ul>
</div>
</div>
<div class="barre_titre">
<a href="#">
pour vous, lg vous propose
</a>
<div class="print">
<a href="#">imprimer la liste</a>
</div>
</div>
<div id="container">
<?php echo CHtml::beginForm();?>
<div class="onglet">
<ul class="menu">
<?php $i = 1;
foreach ($data as $categorie) {?>
<li class="active">
<div class="onglet<?php echo $i;?>">
<img alt="no-picture" src="<?php echo $categorie->image;?>" />
<h4><?php echo CHtml::ajaxLink(
$categorie->titre,
Yii::app()->createUrl('getproduit'),
array('type'=>'POST',
'dataType' =>'json',
'enableAjaxValidation'=>true,
'update'=>'#carousel_container .contentWrapper #carousel_inner',
'data'=>'js:jQuery(".menu li h4 a").serialize()',
'success'=>'function(data){ $("#carousel_container li").text(data);}',
'error'=>'function(a,b,c){alert(b)}'
));?></h4>
</div>
</li>
<?php $i++; }?>
</ul>
</div>
</div>
<div class="carousel_tv" id="carousel_container">
<div class="contentWrapper">
<div id="carousel_inner">
<ul id="carousel_ul">
<li>
<div class="carousel_pic">
<img alt="no-picture" src="images/image1.png" />
<div>
<h3>gamme le5510</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius nulla eu neque porttitor in mattis lectus pulvinar. </p>
</div>
</div>
</li>
<li>
<div class="carousel_pic">
<img alt="no-picture" src="images/image2.png" />
<div>
<h3>gamme le5510</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius nulla eu neque porttitor in mattis lectus pulvinar. </p>
</div>
</div>
</li>
<li>
<div class="carousel_pic">
<img alt="no-picture" src="images/image3.png" />
<div>
<h3>gamme le5510</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius nulla eu neque porttitor in mattis lectus pulvinar. </p>
</div>
</div>
</li>
<li>
<div class="carousel_pic">
<img alt="no-picture" src="images/image1.png" />
<div>
<h3>gamme le5510</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius nulla eu neque porttitor in mattis lectus pulvinar. </p>
</div>
</div>
</li>
<li>
<div class="carousel_pic">
<img alt="no-picture" src="images/image2.png" />
<div>
<h3>gamme le5510</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius nulla eu neque porttitor in mattis lectus pulvinar. </p>
</div>
</div>
</li>
<li>
<div class="carousel_pic">
<img alt="no-picture" src="images/image3.png" />
<div>
<h3>gamme le5510</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius nulla eu neque porttitor in mattis lectus pulvinar. </p>
</div>
</div>
</li>
<li>
<div class="carousel_pic">
<img alt="no-picture" src="images/image1.png" />
<div>
<h3>gamme le5510</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius nulla eu neque porttitor in mattis lectus pulvinar. </p>
</div>
</div>
</li>
<li>
<div class="carousel_pic">
<img alt="no-picture" src="images/image2.png" />
<div>
<h3>gamme le5510</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius nulla eu neque porttitor in mattis lectus pulvinar. </p>
</div>
</div>
</li>
<li>
<div class="carousel_pic">
<img alt="no-picture" src="images/image3.png" />
<div>
<h3>gamme le5510</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius nulla eu neque porttitor in mattis lectus pulvinar. </p>
</div>
</div>
</li>
</ul>
</div>
<div>
<h1>No Content</h1>
</div>
<div>
<h1>No Content</h1>
</div>
</div>
</div>
</div>
<?php echo CHtml::endForm();?>
数据通过xml显示。
控制器:
public function actionGetproduit(){
$obj_produit = new Gamme();
$produits = $obj_produit->get_produits('tv');
foreach ($produits as $data){
echo CHtml::tag('produit',array('style'=>'display:block'),CHtml::encode($data),true);
}
}
我需要从控制器发送的数据显示在视图中..
但是无法做到这一点,任何帮助都是如此。
谢谢: - (
答案 0 :(得分:0)
对于ajax返回,您通常可以使用renderPartial或回显结果,但是CHtml :: tag函数通常会传递标记名称的HTML对象,请参阅{{3} }或here但看起来您的函数需要JSON,因此您需要将结果输出为JSON,请参阅here。如果这不是问题,您可能需要解释一下。
答案 1 :(得分:0)
通常情况下,使用Yii on ajax按钮或链接,或者说情况可能是什么,你会成功的
array('success'=>'js:function(data) {
jQuery("div#status").html(data);
}
在控制器内部,您可以将响应回显给您的视图。还要确保在视图中加载了jQuery!